For some reason, whenever I try and pack my structs using attribute((packed)), the default padding remains.
For example:
#include <iostream> struct testa { char x; long y; }; struct __attribute__((__packed__)) testb { char x; long y; }; int main() { std::printf("no __attribute__: %d\nwith __attribute__: %d", sizeof(testa), sizeof(testb)); }
The values of both no attribute and attribute is 8, though I would expect it to be 8 and 5.
If I use #pragma pack(push, 1) and #pragma pack(pop), I get the expected result.
I ran into a similar issue. Looks like a gcc bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54589
Fix for me was to use "attribute((gcc_struct,packed))" instead
note: attribute should have two underscores before and after, SF editor messes that up
Last edit: Rob Turk 2017-02-25