CPP inconsistency
Daniel Jacobowitz
drow@false.org
Tue Apr 19 14:59:00 GMT 2005
On Tue, Apr 19, 2005 at 03:28:07PM +0200, Etienne Lorrain wrote:
> Hi,
>
> Just a minor thing, but I hit this problem times to times, I know
> the CPP preprocessor has no warning like "end of line ignored"...
> GCC-3.3.5 and 3.4.3.
This is just order of operations.
> etienne@cygne:~/projet$ cat > tmp.c
> #define OPTION1 0x0001
> #define OPTION2 0x0002
> #define OPTION3 0x0004
> #define OPTION4 0x0008
>
> #define CONFIGURATION (OPTION1 | OPTION3)
> // There is the problem: the "== 0" is ignored
> #if CONFIGURATION & OPTION2 == 0
> #warning OPTION2 unset
> #else
> #warning OPTION2 set
> #endif
That's #if (1 | 4) & (2 == 0). 2 != 0, so 5&0 == 0.
--
Daniel Jacobowitz
CodeSourcery, LLC
More information about the Gcc
mailing list