Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Both the compiler and the CPU can reorder code, as long as the results don't change from the perspective of the code that is executing.

For example, a compiler could take the following code:

    global_x = 1;
    global_y = 2;
    global_x = 3;
And change it into:

    global_x = 3;
    global_y = 2;
Compilers on all platforms reorder statements like this. You can prevent this by making your variables `volatile`, but 99% of the time when you write the word "volatile" in your code you're making a mistake.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: