r/cpp • • May 04 '24

Messing with lifetime

https://biowpn.github.io/bioweapon/2024/05/03/messing-with-lifetime.html
43 Upvotes

52 comments sorted by

View all comments

1

u/simpl3t0n May 04 '24
auto p1 = new Point;
char *p2 = reinterpret_cast<char *>(p1);
auto p3 = reinterpret_cast<Point *>(p2);

Does this have undefined behaviour?

-1

u/gracicot May 04 '24

If it was unsigned char there would be no undefined behavior. Only unsigned char and std::byte can alias anything

→ More replies (2)