Hacker News new | ask | show | jobs
by sprw121 4136 days ago
Or we could use __attribute__((packed))?
4 comments

That directly trades size for less efficient code. The structure packing described in the article keeps the same code efficiency while decreasing the size.

There are good reasons (as mentioned in the article) for this feature but it's not equivalent to manual structure packing.

That is not standard C but a GCC extension, although clang probably supports it.
#pragma(pack) or __attribute__((packed)) still won't re-order structure fields for optimal alignment. The directive/extension only prevents holes in the structure.
And then we might get fields that cross word boundaries, making every access unaligned or way worse on architectures that haven't got addressable bytes.