Home > Mobile >  I am trying to determine is C is OK with '!' in its precompiler
I am trying to determine is C is OK with '!' in its precompiler

Time:11-23

The line in question is:

#if ! defined(_VALUE)
    foo = 23;
#endif

It seems to build, but I am not sure its behavior is as expected.

CodePudding user response:

Your example tells the preprocessor to exclude the text if "_VALUE" is defined; else to include it.

Most compilers give you an option to "display preprocessor output", e.g. "-E" for gcc:

x.c

#if ! defined(MY_DEFINITION)
    foo = 23;
#endif

Sample output:

$ gcc -E x.c
# 1 "x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "x.c"

    foo = 23;

$ gcc -E -DMY_DEFINITION x.c
# 1 "x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "x.c"

Here is a good overview: C - Preprocessors

  • Related