#ifdef question

Discussion in 'C Programming' started by Mark, Feb 16, 2012.

  1. Mark

    Mark Guest

    Hello,

    I see constructions like:

    #ifdef FOO || defined BAR
    ....
    #endif

    and compiler's complaints "warning: extra tokens at end of #ifdef
    directive", obviously it should be:

    #if defined FOO || defined BAR
    ....
    #endif

    Does the standard explicitly say so? Could you point at the relevant part?
    Thanks.

    Mark
     
    Mark, Feb 16, 2012
    #1
    1. Advertising

  2. Mark

    Mark Guest

    Found myself: C99, 6.10 Preprocessing directives, par.1

    "Mark" <> wrote in message
    news:jhj9ud$c0n$...
    > Hello,
    >
    > I see constructions like:
    >
    > #ifdef FOO || defined BAR
    > ...
    > #endif
    >
    > and compiler's complaints "warning: extra tokens at end of #ifdef
    > directive", obviously it should be:
    >
    > #if defined FOO || defined BAR
    > ...
    > #endif
    >
    > Does the standard explicitly say so? Could you point at the relevant part?
    > Thanks.
    >
    > Mark
    >
     
    Mark, Feb 16, 2012
    #2
    1. Advertising

  3. Mark

    Noob Guest

    Mark wrote:

    > Hello,
    >
    > I see constructions like:
    >
    > #ifdef FOO || defined BAR
    > ...
    > #endif
    >
    > and compiler's complaints "warning: extra tokens at end of #ifdef
    > directive", obviously it should be:
    >
    > #if defined FOO || defined BAR
    > ...
    > #endif
    >
    > Does the standard explicitly say so? Could you point at the relevant part?
    > Thanks.


    (With respect to C89)

    3.8 PREPROCESSING DIRECTIVES

    if-group:
    # if constant-expression new-line group<opt>
    # ifdef identifier new-line group<opt>
    # ifndef identifier new-line group<opt>

    identifier:
    nondigit
    identifier nondigit
    identifier digit

    nondigit: one of
    _ a b c d e f g h i j k l m
    n o p q r s t u v w x y z
    A B C D E F G H I J K L M
    N O P Q R S T U V W X Y Z

    digit: one of
    0 1 2 3 4 5 6 7 8 9

    A line
    #ifdef FOO || defined BAR
    is not accepted by the grammar

    After the identifier, there can only be a new-line.
     
    Noob, Feb 16, 2012
    #3
    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. Replies:
    0
    Views:
    614
  2. Replies:
    1
    Views:
    733
    Kevin Spencer
    May 31, 2005
  3. Replies:
    4
    Views:
    2,365
    Peter Flynn
    Jan 15, 2006
  4. F. Edward Boas

    typedef and #ifdef

    F. Edward Boas, Aug 11, 2003, in forum: C++
    Replies:
    1
    Views:
    973
    Alf P. Steinbach
    Aug 11, 2003
  5. Dale

    Newbie Question about #ifdef

    Dale, Aug 25, 2004, in forum: C Programming
    Replies:
    5
    Views:
    674
    John Bode
    Sep 8, 2004
Loading...

Share This Page