《Cracking the Coding Interview》——第13章:C和C++——题目5

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 }

 

转载于:https://www.cnblogs.com/zhuli19901106/p/3689971.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值