Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For bit-fields, it is implementation-defined whether the specifier int designates the same type as signed int or the same type as unsigned int. Also, C99 requires that "If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int."

In the following example:

...

The type of the expression (bits.a << 24) is compiler dependent and may be either signed or unsigned depending on the compiler's interpretation of the standard.

The first interpretation is that when this value is used as an rvalue (e.g., lvalue = rvalue), the type is "unsigned int" as declared.  An unsigned int cannot be represented as an int, so integer promotions require that this be an unsigned int, and hence "unsigned".

...