【发布时间】:2017-08-08 20:35:10
【问题描述】:
#include <stdio.h>
#define VAR cc
int main(void) {
int ccc = 9;
printf("hell loo %d", VARc);
return 0;
}
我对这段代码的理解意味着预处理器在任何地方找到VAR,它将用cc 替换它,因此printf 将有一个正确定义的变量ccc,但代码错误。有人可以帮忙吗
编辑 1
我得到的错误是
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.)
【问题讨论】:
-
错误信息是什么?
-
请发布您的错误信息
-
您实际上想要达到什么目的?这看起来真的很像XY Problem
-
PSkocik 下面的回答是正确的,但这或多或少是对预处理器的滥用。如果您告诉我们您的实际用例是什么,那么我们可能会建议一个更好的解决方案。
标签: c c-preprocessor preprocessor