ral*_*lph 2 c preprocessor c-preprocessor
#include <stdio.h>
#define VAR cc
int main(void) {
int ccc = 9;
printf("hell loo %d", VARc);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我对这段代码的理解意味着预处理器找到的任何地方VAR都会替换它cc,因此printf会有一个正确定义的变量ccc,但代码会出错.有人可以请帮助
我得到的错误是
test.c: In function ‘main’:
test.c:16: error: ‘VARc’ undeclared (first use in this function)
test.c:16: error: (Each undeclared identifier is reported only once
test.c:16: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
PSk*_*cik 10
那不行.预处理器适用于整个令牌,而不是字符串.
如果要连接,可以执行以下操作:
#include <stdio.h>
#define VAR(End) cc##End // ## does token concatenation inside a pp macro
int main(void) {
int ccc = 9;
printf("hell loo %d", VAR(c));
return 0;
}
Run Code Online (Sandbox Code Playgroud)