As per this https://stackoverflow.com/a/1812932/1814023 writing one member of union and reading another member is undefined behavior.
And as per this https://stackoverflow.com/a/11640603/1814023 type punning is allowed in C99 / C11
I am bit confused on these two posts, which one is correct? Need help in understanding type punning Vs accessing the member of union.
Thanks.
It's implementation-defined in C89:
In C99/C11, it's allowed, although when it's trap representation, the value is indeterminate.