Fatal Error C1017

invalid integer constant expression

The expression in an #if directive either did not exist or did not evaluate to a constant.

When using the #define statement to define a constant, its value must evaluate to an integer constant if it is to be used as the expression in an #if, #elif, or #else compiler directive. For example, this error occurs with the following code fragment:

#define CONSTANT_NAME "YES"
#if CONSTANT_NAME
...
#endif

Because CONSTANT_NAME evaluates to a string constant and not an integer constant, the #if directive generates this error and halts the compiler.

Another notable situation occurs when any constant that is undefined is evaluated by the preprocessor to be zero. If an undefined constant is used inadvertently, unintended behavior may result. For example, in the following code fragment, the result is the reverse of what is actually intended:

#define CONSTANT_NAME YES
#if CONSTANT_NAME
   // Code to use on YES...
#elif CONSTANT_NAME==NO
   // Code to use on NO...
#endif

In this example, YES is undefined, so it evaluates to zero. Therefore, CONSTANT_NAME is also zero. Thus, the #if expression CONSTANT_NAME evaluates to false and the code intended to be used on YES is removed by the preprocessor. Furthermore, because NO is also undefined, it also evaluates to zero, which means that the #elif expression CONSTANT_NAME==NO evaluates to true (0 == 0). This causes the preprocessor to leave the code in the #elif portion of the conditional statement, which is also not the intended behavior.

Tips