Y
Hacker News
new
|
ask
|
show
|
jobs
by
webkike
1608 days ago
I’ve fixed undefined behavior in large C++ code based caused by misaligned reinterpret casts - the solution is to use memcpy
2 comments
allo37
1608 days ago
It's such a good idea that they made a special cast that does just that in C++20:
https://en.cppreference.com/w/cpp/numeric/bit_cast
link
sgerenser
1608 days ago
And in most cases (at least in optimized builds) the memcpy will be optimized out.
link