C/C++: Force Bit Field Order and Alignment

No, it will not be fully-portable. Packing options for structs are extensions, and are themselves not fully portable. In addition to that, C99 §6.7.2.1, paragraph 10 says: “The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined.”

Even a single compiler might lay the bit field out differently depending on the endianness of the target platform, for example.

Leave a Comment