Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a non-field member of a structure or union?

Tags:

c

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.

like image 491
Tim Avatar asked Aug 11 '17 16:08

Tim


1 Answers

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?

like image 188
ecatmur Avatar answered Nov 02 '22 19:11

ecatmur