This is the mail archive of the
mailing list for the GCC project.
Re: CPP inconsistency
On Tue, Apr 19, 2005 at 03:28:07PM +0200, Etienne Lorrain wrote:
> > #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
On Tue, Apr 19, 2005 at 09:33:44AM -0400, Daniel Jacobowitz wrote:
> That's #if (1 | 4) & (2 == 0). 2 != 0, so 5&0 == 0.
Yes, the fact that the bitwise binary operators have a lower
precedence than the relational operators is probably the biggest
botch in C and its derivative languages; I've been C-ing for 20
years, and I still make these kinds of errors from time to time.
GCC has the "suggest parentheses" warning elsewhere (to catch people
writing "if (foo = 0)" and the like; maybe there should be a warning
for this one as well.