Re:“Fiercely resist any further broadening of the scope of t...
by physguy1123 on Monday April 18, 2016 @10:51AM
(#11520333)
In C, yes, type-punning with union is valid. However, in C++, it is considered undefined behavior and may get removed by the compiler if it sees fit.
[ Parent
| on HN ]
Re:“Fiercely resist any further broadening of the scope of t...
by colin_mccabe on Monday April 25, 2016 @12:39AM
(#11562533)
Thanks for the clarification. Do the new C++ standards explicitly discuss this anywhere?
Re:“Fiercely resist any further broadening of the scope of t...
by physguy1123 on Thursday April 28, 2016 @04:50PM
(#11591802)
There's this stackoverflow qanswer: http://stackoverflow.com/questions/11373203/accessing-inacti...
where answers try to distill the standard into something legible by humans. Unsurprisingly, they come to different conclusions.
The overall interpretation in some situations, if you look at things just right, you can do type punning in C++. But it's pretty risky since you're a LOC away from the compiler deleting your function.
Or, you can't really do it at all safely. Which I would conclude from the above anyways.