Question Details

No question body available.

Tags

c language-lawyer

Answers (2)

Accepted Answer Available
Accepted Answer
January 27, 2026 Score: 5 Rep: 234,363 Quality: High Completeness: 50%

The intent of the standard cannot be to make a structure compatible with its flattened form because that would break the language. Consider these structures:

struct s { char x; char y; int z; };
struct s { char x; struct { char y; int z; }; };

In a typical C implementation with four-byte int with four-byte alignment requirement, there would be two bytes of padding in the first structure between y and z, putting z at offset 4. In the second structure, the internal structure needs to have four-byte alignment so that its int can be properly aligned, and it has three bytes of padding between its y and z. Then the outer structure has three bytes of padding between x and the internal structure, putting z at offset 8. Treating these two structures as compatible would not work.

January 27, 2026 Score: 3 Rep: 403 Quality: Low Completeness: 30%

Document N3003 added the relevant text to C23. They do not note any difference of behavior, only that "explicit wording for anonymous structure and union types was added". Therefore, I'm interpreting this as a a clarification, not a divergence.