boot2

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

351-address-of-member-local.c (587B)


      1 typedef unsigned long ulong;
      2 
      3 struct Inner {
      4   ulong first;
      5   ulong second;
      6 };
      7 
      8 struct Outer {
      9   ulong prefix;
     10   struct Inner inner;
     11   ulong suffix;
     12 };
     13 
     14 static struct Outer storage;
     15 
     16 int main(void) {
     17   struct Outer* outer = &storage;
     18   ulong outer_size = sizeof *outer;
     19   struct Inner* inner = &outer->inner;
     20 
     21   if (outer_size != sizeof(struct Outer)) return 4;
     22   inner->first = 0x11223344ul;
     23   inner->second = 0x55667788ul;
     24   if (storage.inner.first != 0x11223344ul) return 1;
     25   if (storage.inner.second != 0x55667788ul) return 2;
     26   if (inner != &storage.inner) return 3;
     27   return 0;
     28 }