13.07.2015 Views

C struct, typedef, enum & union - Tenouk C & C++

C struct, typedef, enum & union - Tenouk C & C++

C struct, typedef, enum & union - Tenouk C & C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

STRUCT, TYPEDEF, ENUM & UNIONAlignment of Bit Fields• If a series of bit fields does not add up to the size of an int, paddingcan take place.• The amount of padding is determined by the alignmentcharacteristics of the members of the <strong>struct</strong>ure.• The following example demonstrates padding.• Suppose that an int occupies 4 bytes (4 x 8 = 32 bits). The exampledeclares the identifier onoffpower to be of type <strong>struct</strong>switching,<strong>struct</strong> switching {unsigned light : 1;unsigned fridge : 1;int count; /* 4 bytes */unsigned stove : 4;unsigned : 4;unsigned radio : 1;unsigned : 0;unsigned flag : 1;} onoffpower ;www.tenouk.com, © 18/93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!