AR# 38592


12.1 EDK - mb-gcc does not properly pack structures using bitfields


When I attempt to pack a variable with bitfields using the "packed" attribute, the variable does not match the size expected.


GNU GCC has a known issue where bitfields on a "char" type variable is not being packed properly. This is documented in the online GCC documentation:

NOTE: The 4.1, 4.2 and 4.3 series of GCC ignore the "packed" attribute on bit-fields of type char. This has been fixed in GCC 4.4 but the change can lead to differences in the structure layout. See the documentation of -Wpacked-bitfield-compat for more information."

Also, note that this can also apply to "enum" types. An "enum" is not defined as being a specific size in the ANSI/ISO C Specification. This means that it could be placed in a "char", "short", or "int" type.

To work around this issue, use an "int" or "short" type rather than a "char" or "enum".
AR# 38592
Date 10/14/2010
Status Active
Type General Article
People Also Viewed