Suppose I have a valid pointer p0
:
T a[10];
T* p0 = &a[0];
I know that I can safely round-trip-cast it like this:
reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p0)) == p0;
But is it safe to do the following?
T* p1 = reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p0) + sizeof(T));
i.e. can I be sure that there is no UB and that p1 == &a[1]
?