1 int a;
2
f()3 int f() {
4 int a;
5 // Undefined variable b
6 // printf("f 0: a = %d b = %d\n", a, b);
7 printf("f 0: a = %d\n", a);
8 a = 2;
9 printf("f 1: a = %d\n", a);
10 }
11
g(int a)12 int g(int a) {
13 printf("g 0: a = %d\n", a);
14 a = 3;
15 printf("g 1: a = %d\n", a);
16 }
17
h(int a)18 int h(int a) {
19 // int a; // gcc 4.3 says error: 'a' redeclared as different kind of symbol
20
21 printf("h 0: a = %d\n", a);
22 a = 4;
23 printf("h 1: a = %d\n", a);
24 }
25
26 // Already defined global
27 // int h() {}
globCheck()28 int globCheck() {
29 fprintf(stdout, "globCheck()\n");
30 }
31
fwdCheck()32 int fwdCheck() {
33 b();
34 // Undefined forward reference
35 // c();
36 }
37
b()38 int b() {
39 printf("b()\n");
40 }
41
nested()42 int nested() {
43 int a;
44 printf("nested 0: a = %d\n", a);
45 a = 50;
46 printf("nested 1: a = %d\n", a);
47 {
48 int a;
49 printf("nested 2: a = %d\n", a);
50 a = 51;
51 printf("nested 3: a = %d\n", a);
52 }
53 printf("nested 4: a = %d\n", a);
54 }
55
main()56 int main() {
57 globCheck();
58 fwdCheck();
59 printf("main 0: a = %d\n", a);
60 a = 5;
61 printf("main 1: a = %d\n", a);
62 f();
63 printf("main 2: a = %d\n", a);
64 g(77);
65 printf("main 3: a = %d\n", a);
66 h(30);
67 printf("main 4: a = %d\n", a);
68 nested();
69 printf("main 5: a = %d\n", a);
70 return 0;
71 }
72