October 23, 2024
Chicago 12, Melborne City, USA
C#

Is it possible to align pointers without violating strict aliasing?


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).

Does this violate strict aliasing in C and C++? And if so, how can this be implemented without violating the rule? (I’m aware of the compiler flags that disable strict aliasing. I’m asking about obeying the rule, rather than disabling it.)



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