“volatile” qualifier and compiler reorderings

后端 未结 4 2128
天涯浪人
天涯浪人 2020-12-03 08:11

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

But what about the cases where other variables are present, which

4条回答
  •  囚心锁ツ
    2020-12-03 08:29

    Volatile is not a memory fence. Assignments to B and C in snippet #2 can be eliminated or performed whenever. Why would you want the declarations in #2 to cause the behavior of #1?

提交回复
热议问题