3 ms·
> it is fine if there actually was an object of that type (or a "similar" type) in that location. That is correct. See my other nearby reply. > So casting to
by MauranKilom 7y ago
> it is fine if there actually was an object of that type (or a "similar" type) in that location.
That is correct. See my other nearby reply.
> So casting to char* and back is fine
Indeed.
> casting to char and then to int-type to inspect multiple bytes is fine as long as alignment plays correctly, ...
Only if the place in memory you are pointing to actually has a live int object. In particular, inspecting the byte representation of an object is fine (including copying the bytes elsewhere, which is why they could just use memcpy instead of reinterpret_cast).
See also http://eel.is/c++draft/basic.types#2 http://eel.is/c++draft/basic.types#2 and surroundings.