变量在宏中与一个立即数进行比较
int a=1;
#if a==1
#define str "hello"
#else
#define str "world"
#endif
在vs中时, 程序是做了else这里。
a==1是true的啊,为什么 会 走else那块的代码呢
[解决办法]
#define是不能这样使用的
你代码里的#if和#else对#define根本就不起作用,你实际上就等于define了2次str,编译器以最后一次为准,也就是world
[解决办法]
。。。。这也行???
执行else就对了,编译的时候a是未定义的。。所以执行else。运行的时候才会执行a=1赋值操作
#include <stdio.h>#define a 1#if a==1#define str "hello"#else#define str "world"#endifvoid main(){ printf ("%s\n", str);}
[解决办法]
要输出world,
#define a 0