boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

135-block-inferred-array.c (718B)


      1 /* Block-scope array with inferred length: `int a[] = {...};`
      2  * Verify (a) sizeof(a) == 16 (4 elements * sizeof(int)),
      3  * (b) all elements readable with the right value,
      4  * (c) sum is correct, and (d) an adjacent local declared right
      5  * after the array is NOT clobbered by the array's initializer
      6  * stores or by any spills emitted during initialization.
      7  */
      8 
      9 int main(int argc, char **argv) {
     10     int a[] = {10, 20, 30, 40};
     11     int sentinel = 0xCAFE;
     12 
     13     if (sizeof(a) != 16) return 1;
     14     if (a[0] != 10) return 2;
     15     if (a[1] != 20) return 3;
     16     if (a[2] != 30) return 4;
     17     if (a[3] != 40) return 5;
     18     if ((a[0] + a[1] + a[2] + a[3]) != 100) return 6;
     19     if (sentinel != 0xCAFE) return 7;
     20     return 0;
     21 }