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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

STRUCT, TYPEDEF, ENUM & UNION• A bit field declaration contains a type specifier followed by anoptional declarator, a colon, a constant integer expression thatindicates the field width in bits, and a semicolon.type-specifier declarator opt : constant-expression;• A bit field declaration may not use either of the type qualifiers,const or volatile.• The following <strong>struct</strong>ure example has four bit-field membersleft, right, front and rear, occupying 4, 3, 4 and 5 bitsrespectively,<strong>struct</strong> direction { // declare direction bit fieldint left : 4; // 00000000 0000XXXXint right : 3; // 00000000 0XXX0000int front : 4; // 00000XXX X0000000int rear : 5; // XXXXX000 00000000};• In this case, total bits is 16, equal to 2 bytes.www.tenouk.com, © 16/93

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

Saved successfully!

Ooh no, something went wrong!