enum while preprocessing

Discussion in 'C Programming' started by Alex Vinokur, Nov 23, 2006.

  1. Alex Vinokur

    Alex Vinokur Guest

    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
     
    Alex Vinokur, Nov 23, 2006
    #1
    1. Advertising

  2. Alex Vinokur

    Richard Bos Guest

    "Alex Vinokur" <> wrote:

    > 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
     
    Richard Bos, Nov 23, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    548
  2. Jerminia
    Replies:
    3
    Views:
    633
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    468
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    427
    Dave Thompson
    Jun 10, 2004
  5. Randy
    Replies:
    1
    Views:
    520
    David Harmon
    Jan 7, 2006
Loading...

Share This Page