Home | History | Annotate | Download | only in src
      1 // Array allocation tests
      2 
      3 void testLocalInt()
      4 {
      5     int a[3];
      6     a[0] = 1;
      7     a[1] = 2;
      8     a[2] = a[0] + a[1];
      9     printf("localInt: %d\n", a[2]);
     10 }
     11 
     12 char a[3];
     13 double d[3];
     14 
     15 void testGlobalChar()
     16 {
     17     a[0] = 1;
     18     a[1] = 2;
     19     a[2] = a[0] + a[1];
     20     printf("globalChar: %d\n", a[2]);
     21 }
     22 
     23 void testGlobalDouble()
     24 {
     25     d[0] = 1;
     26     d[1] = 2;
     27     d[2] = d[0] + d[1];
     28     printf("globalDouble: %g\n", d[2]);
     29 }
     30 
     31 void testLocalDouble()
     32 {
     33     double d[3];
     34     float  m[12];
     35     m[0] = 1.0f;
     36     m[1] = 2.0f;
     37     d[0] = 1.0;
     38     d[1] = 2.0;
     39     d[2] = d[0] + d[1];
     40     m[2] = m[0] + m[1];
     41     printf("localDouble: %g %g\n", d[2], m[2]);
     42 }
     43 
     44 void vectorAdd(int* a, int* b, float* c, int len) {
     45     int i;
     46     for(i = 0; i < len; i++) {
     47         c[i] = a[i] + b[i];
     48     }
     49 }
     50 
     51 void testArgs() {
     52     int a[3], b[3];
     53     float c[3];
     54     int i;
     55     int len = 3;
     56     for(i = 0; i < len; i++) {
     57         a[i] = i;
     58         b[i] = i;
     59         c[i] = 0;
     60     }
     61     vectorAdd(a,b,c, len);
     62     printf("testArgs:");
     63     for(i = 0; i < len; i++) {
     64         printf(" %g", c[i]);
     65     }
     66     printf("\n");
     67 }
     68 
     69 void testDecay() {
     70     char c[4];
     71     c[0] = 'H';
     72     c[1] = 'i';
     73     c[2] = '!';
     74     c[3] = 0;
     75     printf("testDecay: %s\n", c);
     76 }
     77 
     78 void test2D() {
     79     char c[10][20];
     80     int x;
     81     int y;
     82     printf("test2D:\n");
     83     for(y = 0; y < 10; y++) {
     84         for(x = 0; x < 20; x++) {
     85             c[y][x] = 'a' + (15 & (y * 19 + x));
     86         }
     87     }
     88     for(y = 0; y < 10; y++) {
     89         for(x = 0; x < 20; x++) {
     90             printf("%c", c[y][x]);
     91         }
     92         printf("\n");
     93     }
     94 
     95 }
     96 
     97 int main()
     98 {
     99     testLocalInt();
    100     testLocalDouble();
    101     testGlobalChar();
    102     testGlobalDouble();
    103     testArgs();
    104     testDecay();
    105     test2D();
    106     return 0;
    107 }
    108