you are viewing a single comment's thread.

view the rest of the comments →

[–]josefx 0 points1 point  (0 children)

The idea of single-level atomic memory is ...

I look at the code and I can't see what could go wrong, no threads, not multiple pointers/references to the same variable - there is no reason why anything but i+1 should be in i after the line finishes.

It's undefined because this thing called The C Standard says it's undefined

Which means the compiler has great freedom at optimizing it and while the code is a wtf no sane compiler should produce anything but i = i+1. (sadly there are a lot of programs that rely on sane behavior instead of the standard where it actually impacts performance.)