→ WanCW: linedocs/cpp/Stringification.html 10/06 17:53
修改如下
#include <stdio.h>
#include <stdlib.h>
#define EXP US
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
int main(void) {
WARN_IF(EXP);
return EXIT_SUCCESS;
}
結果
gcc test.c -o test
test.c: In function ??main??:
test.c:15: error: ??US?? undeclared (first use in this function)
test.c:15: error: (Each undeclared identifier is reported only once
test.c:15: error: for each function it appears in.)
請教有什麼地方需要更改? 感恩
※ 編輯: ck49 (111.249.108.83), 10/06/2015 18:54:50
推 yvb: gcc -DREG=\"US\" hello.c -o hello 10/06 19:00
→ yvb: 若確實要使用 gcc -DREG=US ... 的方式, 那 C 就要改成 10/06 19:19
→ yvb: #define STR(X) #X 10/06 19:19
→ yvb: #define S(X) STR(X) 10/06 19:19
→ yvb: printf("%s\n", S(REG)); 10/06 19:20
→ yvb: 這樣 S(REG) 才會轉成 "US" 10/06 19:21