Article ID: 60252 - View products that this article applies to.
This article was previously published under Q60252
This article has been archived. It is offered "as is" and will no longer be updated.
In Microsoft C, you can initialize the values of an entire bitfield structure as an integer in several ways:
In Microsoft C, bitfields are stored in word-sized blocks with the least significant bit representing the first bit of the bitfield. For example, the bitfields in bitstruct, defined below in the example, are stored as follows:
Assigning the integer 0x4c to this structure results in the following bit pattern:
< p4 > < p3 > < p2> <p1> |?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|?|
The bitfields are given the following respective values:
If the number of bits needed for a bitfield structure exceeds 16 in code compiled for MS-DOS or Windows, words will be added as needed to provide room for the structure with no single bitfield crossing a word boundary. Microsoft C/C++, 32-bit Edition, stores bitfield structures in double word values. If the field requires more than 32 bits, the compiler uses additional double words as needed.
p1=0 p2=3 p3=2 p4=0
NOTE: There is no "standard" for storing bitfields in memory; therefore, any program that depends on a particular storage method is not portable to systems that use a different method.
Article ID: 60252 - Last Review: February 27, 2014 - Revision: 2.1