This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CPP inconsistency


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]