News for hackers. Stuff that matters.
Re:Everything in C is undefined behavior by thayne on Wednesday May 20, 2026 @04:08AM (#48204599)
On hardware that doesn't support it, misaligned loads could be compiled to multiple loads and shifts. Probably not great for performance, and it doesn't work if you need it to be atomic, but it isn't impossible.
Re:Everything in C is undefined behavior by gizmo686 on Wednesday May 20, 2026 @04:33AM (#48204740)
That still requires detecting when a misaligned load happens.
Re:Everything in C is undefined behavior by IshKebab on Wednesday May 20, 2026 @07:05AM (#48205844)
That is only really possible if you know the pointer is misaligned at compile time (which does happen, e.g. for packed structs). The examples in the article are for runtime misalignment. It would be crazy to generate code so that every function checked if every access was aligned at runtime.

(Note the normal way to handle that if the hardware doesn't actually support it is for the access to trap and then the OS or firmware emulates it.)