6

From K&R The C Programming Language:

A non-field member of a structure or union may have any object type.

A field member (which need not have a declarator and thus may be unnamed) has type int , unsigned int , or signed int , and is interpreted as an object of integral type of the specified length in bits; whether an int field is treated as signed is implementation-dependent.

...

A non-field member of a structure is aligned at an addressing boundary depending on its type; therefore, there may be unnamed holes in a structure.

  1. I thought that the members of a structure or union are called its fields. So what is a non-field member of a structure or union? How is it different from a field member?
  2. Can you explain "A non-field member of a structure or union may have any object type" with some examples?
  3. Does the second sentence in the quote mean that a field member can only have type int, unsigned int, or signed int?
  4. The last sentence in the quote mentions that a non-field member is aligned. Is a field member aligned? If not, how is a field member stored in memory?

Thanks.

Tim
  • 88,294
  • 128
  • 338
  • 543

1 Answers1

7

A field member is nowadays called a bit field member:

int i : 3;      // named bit-field member
int : 5;        // unnamed bit-field member
int j;          // non-bit-field member
const char *s;  // non-bit-field member, non-integer type

When to use bit-fields in C?

chux - Reinstate Monica
  • 127,356
  • 13
  • 118
  • 231
ecatmur
  • 145,219
  • 25
  • 281
  • 356