TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

SR:  8.3#4Checked automatically with code checker

Synopsis:Do not use bit fields.
Language:C
Severity Level:1
Category:DECLARATIONS


Description:

The behaviour of bit fields is highly machine and compiler dependent. C gives no guarantee of the ordering of fields within machine words, so if you do use them for the latter reason, you program will not only be non-portable, it will be compiler-dependent too. The Standard says that fields are packed into ‘storage units’, which are typically machine words. The packing order, and whether or not a bitfield may cross a storage unit boundary, are implementation defined. To force alignment to a storage unit boundary, a zero width field is used before the one that you want to have aligned.

Bitfields can require a surprising amount of run-time code to manipulate these things and you can end up using more space than they save.