Was just reading about some anonymous structures and how it is isn't standard and some general use case for it is undefined behaviour...
This is the basic case:
struct Point {
union {
struct {
float x, y;
};
float v[2];
};
};
So writing to x
and then reading from v[0]
would be undefined in that you would expect them to be the same but it may not be so.
Not sure if this is in the standard but unions of the same type...
union{ float a; float b; };
Is it undefined to write to a
and then read from b
?
That is to say does the standard say anything about binary representation of arrays and sequential variables of the same type.
struct
s in unions are not part of ISO-C++ (although they are supported by many compilers as an extension). – Anticipationstruct
a name, and his question is still just as valid. – Silber