Good point. I was just pointing out that most people would not consider a struct to be a basic data type that's unionable in this context.
From now on I will assume all the people cursing me are secretly impressed! I'll enjoy life more that way.
Good point. I was just pointing out that most people would not consider a struct to be a basic data type that's unionable in this context.
From now on I will assume all the people cursing me are secretly impressed! I'll enjoy life more that way.
Ok, seems I'm wrong somewhat. in N1256 (a post-C99 draft), there's footnote 82 which says:So it appears to be valid, as long as the accessed value isn't a trap representation in the type you're using to access the object. Since unsigned chars don't trap, you could determine endianess this way, like nonoob said, I think.If the member used to access the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the newtype as described in 6.2.6 (a process sometimes called "type punning"). This might be a trap representation.
Also, there's a completely different part that condones the use of accessing similar structs in a union:Note that this depends on whether or not the definition of the union is visible, which wouldn't be hard in most circumstances, I guess.Originally Posted by 6.5.2.3p5