The discussion focuses on undefined behavior in C illustrated by whether a compiler may hoist a division ahead of a volatile store to x. Kazinator argues the division is not a language-defined visible effect, so reordering is permitted and mentioning that a register used to toggle divide-by-zero exceptions doesn't change that. Uecker replies that a division that would trap (divide-by-zero) can alter observable behavior, and compilers already avoid hoisting potentially trapping operations above function calls; he says the real problem was earlier compilers failing to apply the same protection to volatile accesses (LLVM was fixed, GCC reportedly still had the issue). Wahern insists volatile should provide a minimal barrier to prevent reordering of operations that affect hardware state.
Commenters also raised broader concerns and desired language features. Childintime condemned silent code removals caused by UB, arguing they make C brittle for embedded use and demand expertise to avoid breakage. Codedokode advocated for simple generics and RAII to reduce duplication and automate deallocation. Wahern referenced a prior comment from Martin and noted that C23’s clarifications (fn#150) treat volatile as not a general memory barrier but imply UB may force preserving sequence around volatile accesses.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.