Why does #define INVALID_VALUE -999; give a syntax error when used?

后端 未结 6 2120
长发绾君心
长发绾君心 2020-12-11 22:40

I am trying to compare to a defined constants in C, and I have simplified my program to the following:

#include \"stdio.h\"
#include \"stdlib.h\"
#define INV         


        
6条回答
  •  醉酒成梦
    2020-12-11 23:21

    Remove the semicolon from your INVALID_VALUE definition.

    Macros are replaced lexically (character-by-character) with no understanding of the syntax around them. Your macro INVALID_VALUE is set to -999;, so your if line expands the macro to:

    if (test==-999;)
    

    which is invalid C syntax.

提交回复
热议问题