Hacker News new | ask | show | jobs
by _pmf_ 4141 days ago
> sort structure elements by size/alignment, biggest first

This does not work if I'm using structure packing to align my structs with an existing protocol (i.e. a protocol that does not have the kind of "holes" that an unpacked struct might have).

1 comments

I find this a very strange response: "this technique doesn't work if I have to comply with an external standard." Fine, then don't use the technique.

Although, I believe the more common approach is to define two structs: one using the packed standardized layout, and one using a layout more suited for whatever you're actually doing. In that case, you may wish to consider sorting the elements by size and alignment for the internal use-only layout.