Edward Diener <eldlistmailingz@xxxxxxxxxxxxxx> writes: > On 8/31/2011 3:07 PM, Ian Lance Taylor wrote: >> 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. > > You may be correct but then clearly #if - #elif - #endif works > differently than #if - #else - #if - #endif - #endif, and that seems > odd. Also I would have thought that an #if branch taken would have > precluded the evaluation of an #elif statement and branch just as it > precludes the evaluation of an #else branch. The standard could have been written as you describe, but by my reading it was not. Ian