enum while preprocessing

A

Alex Vinokur

A program below prints "Second".
A preprocessor doesn't know BBB,
but it seems that it (preprocessor) uses 0 unstead of BBB.
Why doesn't the preprocessor produce error/warning: "BBB is indefined"?


====== foo.c ======
#include <stdio.h>

#define AAA 1

enum
{
BBB = 2
};


int main ()
{
#if (BBB > AAA)
printf ("First\n");
#else
printf ("Second\n");
#endif
return 0;
}
===================

Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
 
R

Richard Bos

Alex Vinokur said:
A program below prints "Second".
A preprocessor doesn't know BBB,
but it seems that it (preprocessor) uses 0 unstead of BBB.
Why doesn't the preprocessor produce error/warning: "BBB is indefined"?

Because converting unknown preprocessing identifiers to 0 is what it's
supposed to do. RTFS. From C99, 6.10.1#3: "After all replacements due to
macro expansion ... all remaining identifiers are replaced with the
pp-number 0".

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top