Assuming alignment
is a power of 2, looking for the next properly aligned address can be done using this expression:
(address + alignment - 1u) & ~(alignment - 1u)
However, in order to perform it, the address needs to be cast to uintptr_t
(void*
and char*
won’t do).
Do C and C++ differ with respect to the legality of using such an expression?
You need to sign in to view this answers
Leave feedback about this