|
|
|
|
|
by TeMPOraL
2958 days ago
|
|
Wow, never realized the pointer cast version is undefined behaviour in C. Is C++ equivalent via reinterpret_cast undefined behaviour too? Back in my C++ days, I would much prefer pointer-cast to union-struct, because the latter was subject to alignment/padding issues you mention, while for the former, I know of no desktop architecture that could mess up a int* -> float* cast. I'm also doubly surprised because being able to do that stuff is what I'd consider the selling point of C/C++ over higher-level languages. |
|
Yeah, C and C++ aren't the language most people think they are, and the strict aliasing rules are the most clear manifestation of that.