3 ms·
That is well-defined. "One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial
by Veedrac 8y ago
That is well-defined.
"One special guarantee is made in order to simplify the use of unions: if a union contains several structures that share a common initial sequence (see below), and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them anywhere that a declaration of the complete type of the union is visible. Two structures share a common initial sequence if corresponding members have compatible types (and, for bit-fields, the same widths) for a sequence of one or more initial members."
- rcxdude 8y agoThis does technically require that a union of those structs exists, even though it is not used. I don't know of any compiler for which this actually makes a difference though.
- Veedrac 8y agoAh, I misunderstood the context, you are right to clarify this.
- ufo 8y agoI checked and we actually have a give union for everything. I didn't mention it because I accidentally got rid of it when simplifying my question (the original is full of macros). Looks like we are in the clear! :)