From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris BeHanna To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: preprocessor/3049: Conditional compilation using "#if A==B"broken on i386 Red Hat 7.0. Date: Mon, 04 Jun 2001 16:06:00 -0000 Message-id: <20010604230601.19596.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg00104.html List-Id: The following reply was made to PR preprocessor/3049; it has been noted by GNATS. From: Chris BeHanna To: Neil Booth Cc: Subject: Re: preprocessor/3049: Conditional compilation using "#if A==B" broken on i386 Red Hat 7.0. Date: Mon, 4 Jun 2001 19:02:32 -0400 (EDT) On Mon, 4 Jun 2001, Neil Booth wrote: > behanna@zbzoom.net wrote:- > > > #if BYTE_ORDER == BIG_ENDIAN > > // stuff > > #endif > > #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN > > // stuff > > #endif > > > results in both sections of code getting processed on Red Hat 7.0 if > > _XOPEN_SOURCE is defined. The problem does not occur if _XOPEN_SOURCE > > is not defined. The attached program reproduces this problem. > > That raises the obvious question: can you tell me what are the values > of BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER and PDP_ENDIAN when you > define _XOPEN_SOURCE? (e.g. put them through a printf). > > I'd be extremely suprised if this is a CPP bug, but if it is we need > to fix it quickly. The test program won't even compile with the following lines added after the last #endif and -D_XOPEN_SOURCE on the compile line: cout << "BIG_ENDIAN = " << BIG_ENDIAN << endl; cout << "LITTLE_ENDIAN = " << LITTLE_ENDIAN << endl; cout << "PDP_ENDIAN = " << PDP_ENDIAN << endl; cout << "BYTE_ORDER = " << BYTE_ORDER << endl; I get the following errors: /home/cbehanna/t.cpp: In function `int main (int, char **)': /home/cbehanna/t.cpp:15: `BIG_ENDIAN' undeclared (first use this function) /home/cbehanna/t.cpp:15: (Each undeclared identifier is reported only once for each function it appears in.) /home/cbehanna/t.cpp:16: `LITTLE_ENDIAN' undeclared (first use this function) /home/cbehanna/t.cpp:17: `PDP_ENDIAN' undeclared (first use this function) /home/cbehanna/t.cpp:18: `BYTE_ORDER' undeclared (first use this function) It of course compiles just fine if -D_XOPEN_SOURCE is omitted. This explains why both sections of code are executed: they effectively evaluate to #if 0 == 0. In endian.h, we find the following: #ifdef __USE_BSD # define LITTLE_ENDIAN __LITTLE_ENDIAN # define BIG_ENDIAN __BIG_ENDIAN # define PDP_ENDIAN __PDP_ENDIAN # define BYTE_ORDER __BYTE_ORDER #endif Of course, __USE_BSD is not defined when _XOPEN_SOURCE is defined. This breaks a lot of things, not just endian.h. Looks like Red Hat screwed the pooch. I suppose it would make sense at this point to report this to Red Hat and close out the PR. Sorry about that. -- Chris BeHanna Software Engineer (Remove "bogus" before responding.) behanna@bogus.zbzoom.net I was raised by a pack of wild corn dogs.