What is a field member or union?

From K & R C Programming Language:

A non-user member of a structure or union can have any type of object.

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

...

The non-field structure element is aligned along the addressing boundary depending on its type; therefore, there may be unnamed holes in the structure.

  • I thought that members of a structure or union are called its fields. So what is a non-field member of a structure or union? How does it differ from a field member?
  • Can you explain that “a member that is not a member of a structure or association can have any type of object” with some examples?
  • The second sentence in the quote means that a field member can only have type int, unsigned int, or signed int?
  • The last sentence in the quote mentions that the member without margins is aligned. Is a field element aligned? If not, how are member fields stored in memory?

Thanks.

+5
source share
1 answer

The field member is now called the bit field :

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?

+7
source

Source: https://habr.com/ru/post/1270792/


All Articles