OiO.lk Blog C# Do C and C++ differ on the legality of aligning pointers at runtime?
C#

Do C and C++ differ on the legality of aligning pointers at runtime?


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

Exit mobile version