News for hackers. Stuff that matters.
Re:The Lost Art of Structure Packing (2018) by saalweachter on Monday April 27, 2020 @10:30AM (#22996139)
In my first job, there was an interesting bug introduced by an un-terminated pragma-pack in a header file.

Because not every structure was packed, depending on your include order, some structures would be packed differently in different compilation units.

Except, for the only structures this happened for, the packed packing was coincidentally the same as the default packing ... when the program was compiled 32-bits. Attempting to switch from a 32-bit executable to a 64-bit executable resulted in mysterious segfaults as different compilation units disagreed on where different fields were.

Fun times!

Re:The Lost Art of Structure Packing (2018) by gambiting on Monday April 27, 2020 @10:34AM (#22996175)
>> some structures would be packed differently in different compilation units.

<shivers violently>

Re:The Lost Art of Structure Packing (2018) by karlding on Monday April 27, 2020 @01:55PM (#22998182)
This is why I always use static_assert [0] to assert on the struct size in projects using C11+, or use a macro to create my own (using the negative array size trick) to cause a compile error if I can't use C11 as a sanity check for these cases. This saves a lot of potential headaches.

[0] https://en.cppreference.com/w/c/language/_Static_assert