Christopher Miller
Christopher Miller

Reputation: 3461

Is it UB to reinterpret_cast a T* to a uintptr_t, reinterpret_cast that uintptr_t to a void*, then static_cast that void* back to a T*?

I am writing a C++ tagged pointer. I have a question about whether the operations I use to implement its basic functionality cause undefined behavior:

So, in summary, I am performing the following transformations on a T*:

Does any of this result in undefined behavior? Additionally, am I using reinterpret_cast and static_cast correctly, in their intended use cases?

Upvotes: 6

Views: 984

Answers (0)

Related Questions