【发布时间】:2012-12-26 10:17:12
【问题描述】:
我要创建表格的几个变量:
static char fooObjectKey;
static char bazObjectKey;
static char wthObjectKey;
static char myObjectObjectKey;
...
所以我写了
#define defineVar(x) static char #x ObjectKey
defineVar(foo);
defineVar(baz);
defineVar(wth);
defineVar(myObject);
但我收到错误:Expected identifier or }
我在这里做错了什么? :) 任何帮助表示赞赏
【问题讨论】:
-
大多数编译器可以显示预处理器的结果。在尝试完全理解复杂的宏时,这是非常宝贵的。
-
我在 Xcode 中使用 LLVM,你知道我怎样才能看到结果吗? :)
-
@nacho4d with gcc 是
gcc -E source.c我认为clang 是一样的,因为clang 提供了与gcc 兼容的驱动程序所以clang -E source.c。 -
在 Xcode 中找到了如何做到这一点! stackoverflow.com/questions/5937031/xcode-4-preprocessor-output 见@Steven Hepting 的回答