Re: cpp oddness
On Sun, Feb 09, 2003 at 12:40:07PM -0500, Clint Adams wrote:
> > The output of "cpp test.c" on the attached file:
>
> And cpp -Wundef test.c:
>
> # 1 "test.c"
> # 1 "<built-in>"
> # 1 "<command line>"
> # 1 "test.c"
> test.c:5:2: warning: #warning TEST_FIVE defined
> test.c:8:2: warning: #warning TEST_NINE defined
> # 15 "test.c"
> test.c:24:6: warning: "TEST_FOUR" is not defined
> test.c:24:19: warning: "TEST_SEVEN" is not defined
> test.c:25:2: warning: #warning 4 and 7 claim to be equal
> enum __stuff { TEST_FOUR = 4, TEST_SEVEN = 7 };
> # 28 "test.c"
> test.c:33:2: warning: #warning TEST_THREE defined
> test.c:36:2: warning: #warning TEST_EIGHT defined
> test.c:39:6: warning: "TEST_THREE" is not defined
> test.c:39:20: warning: "TEST_EIGHT" is not defined
> test.c:40:2: warning: #warning 3 and 8 claim to be equal
> enum __stuffandnonsense { TEST_THREE = 3, TEST_EIGHT = 8 };
>
> Note the contradiction.
No bugs. You may want to pick up a copy of the standard - I'm not sure
offhand if any of this is in the GCC manual... aha, it is. Try "info
cpp-3.2 If".
Any identifier without a definition is considered to be 0 in an #if.
Macro substitution is performed on TEST_THREE, which converts it to the
identifier TEST_THREE - still not #define'd. So it's 0.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
Reply to: