8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C 言語のvolatile について

Posted at

volatile とは ?

変数の操作時の最適化を抑制する。

どいうこと ?


(例)
var1 = 0x01;
var1 = 0x02;
var2 = 0x04;

[volatile なし(最適化がかかる場合)]
コンパイラによって以下の処理に変換されてしまう可能性がある。

1. var1 = 0x01 は不要と判断され削除されるケース
  var1 = 0x02;
  var2 = 0x04;
2. var1 と var2 に依存関係はないので順番を変更されるケース
  var2 = 0x04;
  var1 = 0x02;

[volatile あり(最適化がかからない場合)]
記述通りの順番で処理が行われる。
  var1 = 0x01;
  var1 = 0x02;
  var2 = 0x04;
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?