Example:
std::ptrdiff_t dist(void* a, void* b)
{
return static_cast<std::uint8_t*>(b) - static_cast<std::uint8_t*>(a);
}
Align8Type align8; // alignof(Align8Type) == 8
std::uintptr_t(&align8) & 3; // [1]
dist(nullptr, &align8) & 3; // [2]
Align8Type* p = reinterpret_cast<Align8Type*>(static_cast<std::uint8_t*>(nullptr) + dist(nullptr, &align8));
assert(&align8 == p); // [3]
Assuming std::uint8_t
is supported, are the results of [1] & [2] guaranteed to be 0 and is [3] guaranteed to be true in c++ standard?
If not, what about in practice?