This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: CPP inconsistency
- From: Daniel Jacobowitz <drow at false dot org>
- To: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 19 Apr 2005 09:33:44 -0400
- Subject: Re: CPP inconsistency
- References: <20050419132807.15660.qmail@web26906.mail.ukl.yahoo.com>
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