News for hackers. Stuff that matters.
Re:Writing memory efficient C structs by bluGill on Wednesday July 30, 2025 @09:56PM (#44741605)
I pack structs because the packed layout matches some hardware or network structre and thus I get direct access . This isn't a common case but it exists.
Re:Writing memory efficient C structs by yellowapple on Thursday July 31, 2025 @12:55AM (#44742443)
That case is much more common in embedded/bare-metal programming. A decent chunk of the code I've written so far for getting Zig running on a Nintendo 64 is a bunch of packed structs representing various registers (and a bunch of methods on those structs representing common uses of those registers).

It's also a reasonably common case for parsing binary data formats (e.g. a file's header has fields at exact byte offsets, and it's much faster and easier to just grab all the bytes of that header and interpret those bytes as a packed struct).