4 ms·
Doesn't C have something better than that type punning via union to achieve the same effect? I understand Linus reasoning, but still it's an ugly hack.
by greyman 8y ago
Doesn't C have something better than that type punning via union to achieve the same effect? I understand Linus reasoning, but still it's an ugly hack.
- AstralStorm 8y agoType punning to char* is explicitly allowed. (But going from char* to any other type is not...)
- acqq 8y agoSee other comments, some variant of "type punning via union is not allowed according to the C standard" is what made Linus responding like that. Moreover, even using union for that is a compiler switch in gcc, to avoid compiler following "the standard." Linus points that following the standard is definitely wrong thing to do: "When documented gcc behavior says one thing, and the standard might be unclear, we really don't care one whit about the lack of clarity in some standard." I think the union thing was at least initially implemented as not functioning at all in clang, where developers "followed the standard."