1. 5
  1. 4

    This post talks a lot about ‘the C compiler’ but what it means is ‘the platform ABI’. This is normally documented because it’s required to allow multiple C compilers to interoperate. It’s also weird that it doesn’t mention attributes or pragmas for packing structures. If you want fine-grained control over padding, make a structure packed and add manual padding fields. If you want to minimise padding, sort your fields by size (this works 100% for any primitive types, since these are all power-of-two sized, if you have nested structures then it doesn’t work quite as well).

    Most importantly, if you are actually dependent on the presence or absence of padding then add _Static_asserts using offsetof to guarantee that you get compile failures if these assumptions are violated on any given platform.