summaryrefslogtreecommitdiffstats
path: root/libacc/tests/data/locals.c
blob: f1ef363c487ef691af876c34ad5d34a71093c068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
int a;

int f() {
    int a;
    // Undefined variable b
    // printf("f 0: a = %d b = %d\n", a, b);
    printf("f 0: a = %d\n", a);
    a = 2;
    printf("f 1: a = %d\n", a);
}

int g(int a) {
    printf("g 0: a = %d\n", a);
    a = 3;
    printf("g 1: a = %d\n", a);
}

int h(int a) {
    // int a; // gcc 4.3 says error: 'a' redeclared as different kind of symbol

    printf("h 0: a = %d\n", a);
    a = 4;
    printf("h 1: a = %d\n", a);
}

// Already defined global 
// int h() {}
int globCheck() {
    fprintf(stdout, "globCheck()\n");
}

int fwdCheck() {
    b();
    // Undefined forward reference
    // c();
}

int b() {
    printf("b()\n");
}

int nested() {
    int a;
    printf("nested 0: a = %d\n", a);
    a = 50;
    printf("nested 1: a = %d\n", a);
    {
        int a;
        printf("nested 2: a = %d\n", a);
        a = 51;
        printf("nested 3: a = %d\n", a);
    }
    printf("nested 4: a = %d\n", a);
}

int main() {
    globCheck();
    fwdCheck();
    printf("main 0: a = %d\n", a);
    a = 5;
    printf("main 1: a = %d\n", a);
    f();
    printf("main 2: a = %d\n", a);
    g(77);
    printf("main 3: a = %d\n", a);
    h(30);
    printf("main 4: a = %d\n", a);
    nested();
    printf("main 5: a = %d\n", a);
    return 0;
}