Given an union like:
union {
uint16_t halfwords[32];
uint32_t fullwords[16];
} my_union;
what does the Strict Aliasing rule say about e.g.
my_union.fullwords[0] = 1;
printf("%d", my_union.halfwords[1]);
For purposes of the Strict Aliasing Rule, is my_union.halfwords[1]
considered to be a legitimate access to part of a union, or is it considered to take an address which happens to point just past the first element of halfwords
, and then perform an illegitimate uint16_t
read of that address (which a compiler could then accept as an invitation to do whatever it wants).
It would seem semantically like any sane compiler would have all the information needed to recognize it as being a member of the union, but is there anything in the Standard that would require a compiler to do so?
If it's necessary to pass one of the arrays or a portion thereof to another function, would it still be possible to access the other array via the Union?
If it's necessary to pass one of the arrays to one method, and the other to another method, is there any efficient action which can be performed between those actions to ensure that the compiler doesn't think strict aliasing is violated?