boot2

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

025-deref-postinc.c (636B)


      1 // tests/cc-parse/25-deref-postinc.c — *p++ walking a span (§B.5).
      2 //
      3 // We can't use a[i] (§D.5, owned elsewhere) and we can't span
      4 // `int` locals because cg's per-statement spill slots interleave
      5 // between adjacent local declarations. Instead use a multi-byte int
      6 // holding our three values in its low bytes plus an unsigned-char
      7 // pointer to walk the bytes — pointer scaling is by 1, no scaling
      8 // quirk to dodge.
      9 int main(void) {
     10     int packed = (4 << 16) | (2 << 8) | 1;  // bytes: 1, 2, 4 (LE)
     11     unsigned char *p = (unsigned char *)&packed;
     12     int s = 0;
     13     s += *p++;
     14     s += *p++;
     15     s += *p++;
     16     return s;
     17 }