5 ms·
Some people are allergic to `main() { Foo foo; foo_init(&foo); }` Admittedly, sometimes for good reason - it locks in the ABI.
by o11c 2y ago
Some people are allergic to `main() { Foo foo; foo_init(&foo); }`
Admittedly, sometimes for good reason - it locks in the ABI.
- MathMonkeyMan 2y agoIs that why some structs have "char reserved[16]" data members? I think I saw this in NGINX, though that might have been to allow module compatibility between the open source offering and the paid version.
- o11c 2y agoYes, that slightly improves ABI flexibility, though the fact that callers can still access fields limits that. An alternative is to make the only member `char opaque[16]` (IIRC some locale-related thing in glibc does this, also I think libpng went through a transition of some sort related to this?), but calculating the size can be difficult outside of trivial cases since you can't use sizeof/offsetof.
- liontwist 2y agoABI? Better make it an anonymous struct too. It’s a performance oriented custom memory allocator.
- kazinator 2y agoMainly just the size and alignment. If you make the structure oversized, and with strict alignment, it can be future proofed. Old binary clients will provide a structure big enough and aligned enough for the new version. The dynamic constructor API can allocate the structure exactly sized without the padding.