Hacker News new | ask | show | jobs
by brandmeyer 3981 days ago
Strictly speaking accessing that union both ways ~~~violates the strict aliasing rules~~~ isn't portable. However, it is such a common idiom that GCC and other compilers explicitly allow using unions to get around the strict aliasing rules, so long as the access is always performed through the union.
1 comments

Type punning by casting through a union is allowed by c99/c11 in that the behavior is unspecified(not undefined) and a footnote clarified the behavior to be the expected.

http://stackoverflow.com/questions/11639947/is-type-punning-...