preprocessor

Discussion in 'C Programming' started by sangeeta chowdhary, Jun 30, 2010.

  1. Hi,

    I have compiled this code-

    #include<stdio.h>
    int main()
    {
    #ifdef NOTE
    /* unterminated comment
    int a;
    a=10;
    #else
    int a;
    a=20;
    #endif

    printf("%d\n",a);
    return 0;
    }

    Now,#ifdef fails in this case and the if block doesn't go for
    compilation,still errors in the if block are not permitted,how? Who
    check for these errors? I heard about compile time errors,logical
    errors,run time errors then in which category this error come? If
    syntax error,but compiler checks for syntax error ,but this error is
    displayed before compilation.


    }
    sangeeta chowdhary, Jun 30, 2010
    #1
    1. Advertising

  2. sangeeta chowdhary

    Fred Guest

    On Jun 30, 9:10 am, sangeeta chowdhary <>
    wrote:
    > Hi,
    >
    > I have compiled this code-
    >
    > #include<stdio.h>
    > int main()
    > {
    >   #ifdef NOTE
    >     /* unterminated comment
    >     int a;
    >     a=10;
    >  #else
    >     int a;
    >     a=20;
    >  #endif
    >
    >  printf("%d\n",a);
    >  return 0;
    >
    > }
    >
    > Now,#ifdef fails in this case and the if block doesn't go for
    > compilation,still errors in the if block are not permitted,how? Who
    > check for these errors? I heard about compile time errors,logical
    > errors,run time errors then in which category this error come? If
    > syntax error,but compiler checks for syntax error ,but this error is
    > displayed before compilation.
    >
    >


    Comments are removed BEFORE ifdef's are processed.
    --
    Fred K
    Fred, Jun 30, 2010
    #2
    1. Advertising

  3. sangeeta chowdhary <> wrote:
    >   #ifdef NOTE
    >     /* unterminated comment
    >     int a;
    >     a=10;
    >  #else
    >
    > ...this error is displayed before compilation.


    Translation phase 3 is decomposition into preprocessing
    tokens. Preprocessing directives are not processed until
    translation phase 4. [cf. 5.1.1.2p1]

    --
    Peter
    Peter Nilsson, Jul 1, 2010
    #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. Chris P
    Replies:
    0
    Views:
    428
    Chris P
    Oct 28, 2003
  2. The Weiss Family

    VHDL Preprocessor

    The Weiss Family, Jul 14, 2004, in forum: VHDL
    Replies:
    2
    Views:
    3,191
    The Weiss Family
    Jul 14, 2004
  3. =?Utf-8?B?SSBhbSBTYW0=?=

    C# Preprocessor

    =?Utf-8?B?SSBhbSBTYW0=?=, Mar 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,564
    =?Utf-8?B?SSBhbSBTYW0=?=
    Mar 13, 2005
  4. Replies:
    0
    Views:
    2,655
  5. Cronus
    Replies:
    1
    Views:
    641
    Paul Mensonides
    Jul 15, 2004
Loading...

Share This Page