boot2

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

105-deeper-deref.c (614B)


      1 /* Multi-level pointer indirection and address-of patterns
      2  * frequently seen in tcc.c. */
      3 
      4 int triple_deref(int ***p) { return ***p; }
      5 
      6 int main(int argc, char **argv) {
      7     int x = 42;
      8     int *p = &x;
      9     int **pp = &p;
     10     int ***ppp = &pp;
     11     if (triple_deref(ppp) != 42) return 1;
     12 
     13     /* Modify through three levels. */
     14     ***ppp = 99;
     15     if (x != 99) return 2;
     16 
     17     /* Pointer to array of pointers. */
     18     int a = 1, b = 2, c = 3;
     19     int *arr[3] = { &a, &b, &c };
     20     int **q = arr;
     21     if (*q[0] != 1) return 3;
     22     if (*q[2] != 3) return 4;
     23     *q[1] = 20;
     24     if (b != 20) return 5;
     25     return 0;
     26 }