[英]What is wrong with the following C code
I am using VC2010. 我正在使用VC2010。 I defined FALSE to be false using
我使用以下方式将FALSE定义为false
#define FALSE=false
and then I tried to use it as follows 然后我尝试如下使用它
bool *bPtr;
if(some condition)
*bPtr=FALSE;
the compiler flags FALSE and says "Expected an expression". 编译器标记为FALSE并说“期望表达式”。
I used false instead of the defined 'FALSE' and it accepts it. 我用false代替定义的'FALSE',它接受了它。 I am wondering as what could be the problem.
我想知道可能是什么问题。
You might tell me not to define and so not to use FALSE. 您可能会告诉我不要定义,因此不要使用FALSE。 well, I am not using it.
好吧,我没有使用它。
I just want to know the problem. 我只想知道问题所在。
Just this: 只是这个:
#define FALSE false
with whitespace and without =
. 带空格,不带
=
。
You shouldn't put =
in the definition statement: 您不应将
=
放在定义语句中:
#define FALSE false
The problem is that the preprocessor will replace every FALSE
with =false
, so you will have: 问题是预处理器将每个
FALSE
替换为=false
,因此您将拥有:
*bPtr==false;
And this is not legal as you see. 如您所见,这是不合法的。
try defining like this: 尝试这样定义:
#ifndef (FALSE)
#define FALSE (0)
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.