3 ms·
Type punning with unions was actually forbidden by C89. You were only ever supposed to read the union member which was last written to. This may have been relax
by kbolino 2y ago
Type punning with unions was actually forbidden by C89. You were only ever supposed to read the union member which was last written to. This may have been relaxed in C17; I can only find a draft online, but it allows for type punning in unions as long as the member being read is not longer in size than the member last written to.
- uecker 2y agoIIRC it was supported in C89 and described as implementation-defined and C99 changed the wording and mentions union type punning.
- matheusmoreira 2y agoWhat the standard says doesn't really matter. Only what major compilers do matters. GCC has decreed that type punning through unions is supported, therefore it might as well be standard.