Search code examples
clanguage-lawyerbit-fields

Meaning of 6.3.1.1p2, bullet point 2


6.3.1.1p2 says

The following may be used in an expression wherever an int or unsigned int may be used:

  • An object or expression with an integer type (other than int or unsigned int) whose integer conversion rank is less than or equal to the rank of int and unsigned int.

  • A bit-field of type _Bool, int, signed int, or unsigned int.

What's the intention behind the second bullet point?

Why leave out integer fields of other types whose rank is less than that of int?

Does it mean that I can do e.g.:

printf("%d\n", (struct{ _Bool x:1; }){0}.x);

but not:

printf("%d\n", (struct{ unsigned short x:1; }){0}.x);

Solution

  • Presumably this is because of 6.7.2.1p5:

    A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type. It is implementation-defined whether atomic types are permitted.

    I.e. you can't portably create bit-fields of other types anyway.