Apr 22, 2026

[C++] unaligned pointer convert to more strict alignment is an UB

Never create an unaligned pointer of the struct type.

Its UB to convert from one pointer with less alignment guarantees to another with more, if the underlying pointer is not aligned. 

Everything that happens after that is UB, including arithmetic. 


Reference:
https://eel.is/c++draft/expr.static.cast#12

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.