Are C-unions never complemented at the beginning?

Are there any guarantees in the C99 standard that unions will only ever be complemented at the end, as structures? Accordingly, will the address of the union always be equal to the address of any of its possible members?

+4
source share
3 answers
  • Yes. As you noticed, structures never had an initial fill. The union address always refers to the first element of any component of the union (with appropriate drops), so there can be no addition at the beginning of the union.

  • Yes. Suitably, the union address is also a pointer to any of the elements within the union.

ISO / IEC 9899: 2011

6.7.2.12 Structure and Association Specifications

¶15 , - , , . , , ( -, , ) . , .

¶16 , . at . , , ( , , ), .

¶17 .

+3

:

6.7.2.11-4: , , ( , , )

, .

+2

.

, , ( , , ) .

, C , ( ) . , - .

However, there is no reason to have it there. And, quite obviously, there was no intention to introduce this opportunity. Especially when you consider that the language specification clearly indicates that there is no padding at the beginning of the structures.

+1
source

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


All Articles