Z
zgene
Look at this code:
1. #include<stdio.h>
2.
3. main()
4. { const int *pc;
5. int i = 10;
6.
7. pc = &i;
8. printf("%d\n", *pc);
9.
10. int c = 2;
11. pc = &c;
12. printf("%d\n", *pc);
13. }
If I compile this code with gcc, I get:
myprompt> gcc PtrTest.c
PtrTest.c: In function `main':
PtrTest.c:9: parse error before `int'
PtrTest.c:10: `c' undeclared (first use in this function)
PtrTest.c:10: (Each undeclared identifier is reported only once
PtrTest.c:10: for each function it appears in.)
myprompt>
Whereas g++ compiles it nicely. Look:
myprompt> g++ PtrTest.c
myprompt>
However, if I move Line 10 to Line 6, gcc also compiles it nicely.
So, does g want us to declare all variables at the head of a block? What
a stupid gcc!
1. #include<stdio.h>
2.
3. main()
4. { const int *pc;
5. int i = 10;
6.
7. pc = &i;
8. printf("%d\n", *pc);
9.
10. int c = 2;
11. pc = &c;
12. printf("%d\n", *pc);
13. }
If I compile this code with gcc, I get:
myprompt> gcc PtrTest.c
PtrTest.c: In function `main':
PtrTest.c:9: parse error before `int'
PtrTest.c:10: `c' undeclared (first use in this function)
PtrTest.c:10: (Each undeclared identifier is reported only once
PtrTest.c:10: for each function it appears in.)
myprompt>
Whereas g++ compiles it nicely. Look:
myprompt> g++ PtrTest.c
myprompt>
However, if I move Line 10 to Line 6, gcc also compiles it nicely.
So, does g want us to declare all variables at the head of a block? What
a stupid gcc!