Memory layout of a data structure: Difference between revisions

m
Line 96:
=={{header|C}}/{{header|C++}}==
Note: The order of the fields is implementation-defined (i.e. the first bit might be the least-significant one or the most-significant one). On GCC and MSVC++, the first bit is the least-significant one.
<lang c>struct RS232_data
struct RS232_data
{
unsigned carrier_detect : 1;
Line 111 ⟶ 110:
</lang>
The ":1" gives the number of allocated bits. For unused bits (e.g. pin 11 in the 25-pin version above) the field name can be omitted.
 
Since as stated before the order of bits can't be assured '''but''' it could be important if we need to interact with hardware, the best way is to define ''bit masks''; of course actual writing/reading to/from an hardware "register" greater than a single byte must be done taking care of endianness.
 
=={{header|D}}==