Re: Preprocessor problem or C++ compliant ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Edward Diener <eldlistmailingz@xxxxxxxxxxxxxx> writes:

> Attempting to compile this small example program with gcc, with
> SOME_MACRO defined on the command line:
>
> #if !defined(SOME_MACRO)
> #define MACRO_1() 1
> #else
> #define MACRO_1()
> #endif
>
> #if defined(SOME_MACRO)
> int main() { return 0; }
> #elif MACRO_1() == 1
> int main() { return 1; }
> #endif
>
> gives the error:
>
> eliftest.cpp:9:17: error: operator '==' has no left operand
>
>     "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g 
> -Wno-variadic-macros -DSOME_MACRO -c "eliftest.cpp"
>
> If SOME_MACRO is defined, it seems to me that gcc should not be
> expanding the expression 'MACRO_1() == 1' and reporting an error.

gcc's behaviour matches my reading of the C99 standard.  The standard
says that each #if/#elif condition is checked.  It doesn't say that the
compiler should stop checking conditions after it finds one that is
true.  Instead, it says that the first group which is true is processed.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux