"volatile" qualifier and compiler reorderings

Posted by Checkers on Stack Overflow See other posts from Stack Overflow or by Checkers
Published on 2010-03-29T00:15:40Z Indexed on 2010/03/29 0:23 UTC
Read the original article Hit count: 621

Filed under:
|
|
|

A compiler cannot eliminate or reorder reads/writes to a volatile-qualified variables.

But what about the cases where other variables are present, which may or may not be volatile-qualified?

Scenario 1

volatile int a;
volatile int b;

a = 1;
b = 2;
a = 3;
b = 4;

Can the compiler reorder first and the second, or third and the fourth assignments?

Scenario 2

volatile int a;
int b, c;

b = 1;
a = 1;
c = b;
a = 3;

Same question, can the compiler reorder first and the second, or third and the fourth assignments?

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++