October 24, 2024
Chicago 12, Melborne City, USA
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

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video