summaryrefslogtreecommitdiffstats
path: root/libacc/tests/data/array.c
blob: ca4a7283c1d9313945a3bd9b11afcbbd27c4c311 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Array allocation tests

void testLocalInt()
{
    int a[3];
    a[0] = 1;
    a[1] = 2;
    a[2] = a[0] + a[1];
    printf("localInt: %d\n", a[2]);
}

char a[3];
double d[3];

void testGlobalChar()
{
    a[0] = 1;
    a[1] = 2;
    a[2] = a[0] + a[1];
    printf("globalChar: %d\n", a[2]);
}

void testGlobalDouble()
{
    d[0] = 1;
    d[1] = 2;
    d[2] = d[0] + d[1];
    printf("globalDouble: %g\n", d[2]);
}

void testLocalDouble()
{
    double d[3];
    float  m[12];
    m[0] = 1.0f;
    m[1] = 2.0f;
    d[0] = 1.0;
    d[1] = 2.0;
    d[2] = d[0] + d[1];
    m[2] = m[0] + m[1];
    printf("localDouble: %g %g\n", d[2], m[2]);
}

void vectorAdd(int* a, int* b, float* c, int len) {
    int i;
    for(i = 0; i < len; i++) {
        c[i] = a[i] + b[i];
    }
}

void testArgs() {
    int a[3], b[3];
    float c[3];
    int i;
    int len = 3;
    for(i = 0; i < len; i++) {
        a[i] = i;
        b[i] = i;
        c[i] = 0;
    }
    vectorAdd(a,b,c, len);
    printf("testArgs:");
    for(i = 0; i < len; i++) {
        printf(" %g", c[i]);
    }
    printf("\n");
}

void testDecay() {
    char c[4];
    c[0] = 'H';
    c[1] = 'i';
    c[2] = '!';
    c[3] = 0;
    printf("testDecay: %s\n", c);
}

void test2D() {
    char c[10][20];
    int x;
    int y;
    printf("test2D:\n");
    for(y = 0; y < 10; y++) {
        for(x = 0; x < 20; x++) {
            c[y][x] = 'a' + (15 & (y * 19 + x));
        }
    }
    for(y = 0; y < 10; y++) {
        for(x = 0; x < 20; x++) {
            printf("%c", c[y][x]);
        }
        printf("\n");
    }

}

int main()
{
    testLocalInt();
    testLocalDouble();
    testGlobalChar();
    testGlobalDouble();
    testArgs();
    testDecay();
    test2D();
    return 0;
}