Bitfields

Using bitfields to save memory generally produces additional code. For ANSI-C compliance, bitfields have a type of signed int, thus a bitfield of size 1 is either -1 or 0. This may force the compiler to sign extend operations:

  struct {

  
    int b:0;  /* -1 or 0 */

  
  } B;

  
  int i = B.b; /* load the bit, sign extend it to -1 or 0 */

  

Sign extensions are normally time- and code-inefficient operations.