Reply to post: Re: Ugh!

Keen to go _ExtInt? LLVM Clang compiler adds support for custom width integers

Mike 125

Re: Ugh!

>I turn off alignment with #pragma pack. The resultant code generated by the compiler to access this structure is obviously more complicated,

You're forcing the compiler to use a non-native data representation. That is nearly always a bad idea.

The resultant source code is subtly non-portable and dangerous, giving rise to one of the worst categories of bug: it can come and go depending on something as obscure as the exact alignment of the binary in memory. Even on the local machine, its runtime can vary according to alignment, causing further strange behaviour.

Saving memory by sensible ordering of C structures, is a well explored and explained issue.

The Lost Art of Structure Packing.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2021