Search code examples
cobjectbit-fields

Is a bit-field an object?


According to C11, an object is:

#C11 § 3: Terms, definitions, and symbols
object: region of data storage in the execution environment, the contents of which can represent values.

A bitfield can represent a value, so it should be an object. But, I have been told it was not the case.

What is the correct answer?


Solution

  • 6.2.6.1p2 says "Except for bit-fields, objects are composed of contiguous sequences of one or more bytes [...]", so it seems clear that bit-fields are objects. Similarly, 6.2.6.1p4 refers to "non-bit-field objects".

    3.5p1 defines the bit as the unit of data storage; a bit field is a region of bits so must be a region of data storage. The standard distinguishes between objects and memory locations (a memory location is "either an object of scalar type, or a maximal sequence of adjacent bit-fields all having nonzero width"; 3.14p1) so an object need not have a distinct memory location.