Re:C Puzzles
by JoeAltmaier on Tuesday June 23, 2015 @08:21AM
(#9764134)
Technically, it will print the first N bytes of the float as an int. Where N is the number of bytes ints compile to on the platform. So with knowledge of the platform, the result is entirely predictable.
[ Parent
| on HN ]
Only with knowledge of platform AND compiler, though.
Also these are C puzzles and casting pointers to incompatible types and dereferencing them is undefined behavior. Using memcpy would indeed fix this according to e.g. [1].
[1] http://blog.llvm.org/2011/05/what-every-c-programmer-should-... (section "Violating Type Rules")