Re:The Dangers of Super Smart Compilers
by barrkel on Sunday December 20, 2015 @11:33AM
(#10767437)
Type punning is not fine in C99 - you need to use a correctly typed pointer or a char pointer.
[ Parent
| on HN ]
Re:The Dangers of Super Smart Compilers
by Kristine1975 on Sunday December 20, 2015 @12:52PM
(#10767678)
You're right. Type punning via pointer cast, e.g.
int i = ...
float f = *(float*) &i;
is not fine (violates strict aliasing). Type punning via union, e.g. union { int i; float f; } u;
u.i = ...
float f = u.f;
is, though (but only in C).Just use memcpy :-)