3 ms·
I keep hearing this rumor, but C99 did not erroneously include unions-as-type-punning in a list of undefined behavior. The normative language is unclear, but c
by aidenn0 7y ago
I keep hearing this rumor, but C99 did not erroneously include unions-as-type-punning in a list of undefined behavior. The normative language is unclear, but clarifications were added1][2].
1: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_257.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_257.htm
2: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_283.htm
- quietbritishjim 7y agoThe parent comment seems to be saying that C99 does allow type punning with a union, with an explicit clarification as you say. In C89 it was ambiguous and in C++ it is explicitly disallowed (you are supposed to use memcpy).
- quietbritishjim 7y agoSorry, I misread the parent comment. Now it's too late to delete mine, please ignore.