preprocessor

S

sangeeta chowdhary

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.


}
 
F

Fred

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.
 
P

Peter Nilsson

sangeeta chowdhary said:
  #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]
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top