2014-04-25 19:59

题目:C的关键字volatile有什么用?

解法:搞硬件设计的人好像更关注这个关键字。volatile本身是易变的意思,应该和persistent有反义词关系吧。说一个变量或是函数是易变的,就是说不知道会发生什么变化,所以不要编译器按规则进行优化处理,这就是我对此关键字唯一的了解了。目前为止,我貌似还没有遇到需要用到这个的情景,看来阅读过的代码还是太少。

代码:

1 // 13.5 Explain the "volatile" keyword in C.
2 // Answer:
3 //    1. disable compiler optimization on 'volatile' data.
4 //     2. the data declared as volatile won't be cached in register, because it might be modified in memory by other threads or subprocesses.
5 //    3. 'volatile' is more of an issue to be discussed in DSP design, thus paid less attention than other C keywords.
6 int main()
7 {
8     return 0;
9 }

 

相关文章:

  • 2021-07-27
  • 2021-06-02
  • 2021-06-19
  • 2021-11-11
  • 2021-12-27
  • 2021-11-04
  • 2021-08-24
  • 2021-10-13
猜你喜欢
  • 2021-07-13
  • 2021-05-31
  • 2021-12-26
  • 2021-09-22
  • 2022-01-20
  • 2021-12-07
  • 2021-11-21
相关资源
相似解决方案