#define B 100+B
main()
{
int i= B;
}
I know it's wrong, but just out of curiosity, when I compile it I get this weird error:
"B was not declared in this scope".
Why is it so? If this error was because the compiler removes the macro after its substitution then how does the following code worked fine, when B must have been removed before it was made available to A ?
#define B 100
#define A 100+B
main()
{
int i= B;
int j =A;
}
Here's the output of the preprocessor:
gcc -E x.c
# 1 "x.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "x.c"
main()
{
int i= 100+B;
}
As you can see, it did the substituion. Now comes the compile step which fails because there's no B
declared.
The other code is fine, here's the output:
main()
{
int i= 100;
int j =100+100;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With