i want to know the rule behind the macro substitution
ex:
o/p: P=10Code:#include<stdio.h>
#define p P
int main()
{
int P = 10;
printf("\n P= %d",p);
}
my question is why dont macro substitution dont replace p in printf with P.
Printable View
i want to know the rule behind the macro substitution
ex:
o/p: P=10Code:#include<stdio.h>
#define p P
int main()
{
int P = 10;
printf("\n P= %d",p);
}
my question is why dont macro substitution dont replace p in printf with P.
The preprocessor understands enough of the C language to recognise that printf is a different identifier from p.
Roughly speaking, the preprocessor only substitutes p for P where the p is in a context where it looks like a complete token.
There are 8 phases of Standard C translation
1) Trigraph Replacement
2) Line Splicing
3) Tokenization
4) Macro Expansion and Directive handling
5) Character set mapping
6) String concatenation
7) Translation
8) Linkage
Since tokenization occur prior to macro expansion it does not expand p of printf(). The preprocessor does not parse the source text but it does break it up in tokens for the purpose of locationg macro calls.
The Preprocessor (C/C++)