kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

attr_01_packed_struct.c (534B)


      1 /* __attribute__((packed)) on a struct definition; used as a field of
      2  * another struct. Phase 1 parses but does not honor the attribute, so
      3  * we must return a value that is correct under the *unpacked* layout.
      4  * Unpacked: char (1) + 3 pad + int (4) = 8 bytes; we just declare it
      5  * and return 0 to avoid asserting any specific size. */
      6 struct __attribute__((packed)) S {
      7   char c;
      8   int i;
      9 };
     10 
     11 struct Outer {
     12   struct S s;
     13   int x;
     14 };
     15 
     16 int test_main(void) {
     17   struct Outer o;
     18   o.s.c = 1;
     19   o.s.i = 0;
     20   o.x = 0;
     21   return o.s.i;
     22 }