#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#define CHECK(x,y,n) (x > 0 && x < n && y > 0 && y < n ? 1 : 0))
int main(void)
{
/*char s[5];
int i;
strcpy(s,"abcd");
i = 0;
putchar(s[++i]);*/
int i = CHECK(2,3,10);
printf("%d",i);
return 0;
}
我想声明一个宏来检查两个值 x 和 y 是否在区间内,但是当我尝试编译和构建时,我从编译器中得到这些错误:
line 4 error: expected ',' or ';' before ';' ')' token
最佳答案
宏中多了一个)
。无论如何,我建议将所有宏参数括在括号中以避免优先级问题和其他一些宏陷阱:
#define CHECK(x,y,n) ((x) > 0 && (x) < (n) && (y) > 0 && (y) < (n) ? 1 : 0)
关于c - 检查间隔范围内值的宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32055453/