5 ms·
Or we could use __attribute__((packed))?
by sprw121 12y ago
Or we could use __attribute__((packed))?
- TorKlingberg 12y agoThat is not standard C but a GCC extension, although clang probably supports it.
- grok2 12y ago#pragma(pack) or __attribute__((packed)) still won't re-order structure fields for optimal alignment. The directive/extension only prevents holes in the structure.
- wvenable 12y agoThat 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.
- kryptiskt 12y agoAnd then we might get fields that cross word boundaries, making every access unaligned or way worse on architectures that haven't got addressable bytes.