News for hackers. Stuff that matters.
Re:1.5 is the midpoint between 0 and infinity in Ruby by colejohnson66 on Friday November 27, 2020 @04:00PM (#25232528)
Not true. You actually can. Aliasing is about viewing the same bits as two different types (what `reinterpret_cast`, union-based type punning, and cast pointers do) `memcpy` copies the bits to a new location which doesn’t violate aliasing. I don’t have time to find the reference in the standard, but cppreference.com[0] says it’s ok:

> Where strict aliasing prohibits examining the same memory as values of two different types, std::memcpy may be used to convert the values.

[0]: https://en.cppreference.com/w/cpp/string/byte/memcpy

Re:1.5 is the midpoint between 0 and infinity in Ruby by kazinator on Friday November 27, 2020 @05:18PM (#25233056)
Who is cppreference.com? The domain registration is concealed, just like that of the other dubious site, cplusplus.com.

I don't see any such a claim about memcpy having magic powers in the N4659 C++ draft.

All it says is that the underlying bytes of an object can be copied to an array of char, unsigned char, or std::byte. Then if that array is copied back into the object, the object subsequently holds its original value.

Anything more about memcpy comes from C by reference, and that would be about the last document on Earth to grant definedness and portability to something like this.