《Cracking the Coding Interview》——第13章:C和C++——题目5
2014-04-25 20:07
831 查看
2014-04-25 19:59
题目:C的关键字volatile有什么用?
解法:搞硬件设计的人好像更关注这个关键字。volatile本身是易变的意思,应该和persistent有反义词关系吧。说一个变量或是函数是易变的,就是说不知道会发生什么变化,所以不要编译器按规则进行优化处理,这就是我对此关键字唯一的了解了。目前为止,我貌似还没有遇到需要用到这个的情景,看来阅读过的代码还是太少。
代码:
题目:C的关键字volatile有什么用?
解法:搞硬件设计的人好像更关注这个关键字。volatile本身是易变的意思,应该和persistent有反义词关系吧。说一个变量或是函数是易变的,就是说不知道会发生什么变化,所以不要编译器按规则进行优化处理,这就是我对此关键字唯一的了解了。目前为止,我貌似还没有遇到需要用到这个的情景,看来阅读过的代码还是太少。
代码:
// 13.5 Explain the "volatile" keyword in C. // Answer: // 1. disable compiler optimization on 'volatile' data. // 2. the data declared as volatile won't be cached in register, because it might be modified in memory by other threads or subprocesses. // 3. 'volatile' is more of an issue to be discussed in DSP design, thus paid less attention than other C keywords. int main() { return 0; }
相关文章推荐
- 《Cracking the Coding Interview》——第13章:C和C++——题目6
- 《Cracking the Coding Interview》——第13章:C和C++——题目7
- 《Cracking the Coding Interview》——第13章:C和C++——题目8
- 《Cracking the Coding Interview》——第13章:C和C++——题目1
- 《Cracking the Coding Interview》——第13章:C和C++——题目9
- 《Cracking the Coding Interview》——第13章:C和C++——题目10
- 《Cracking the Coding Interview》——第13章:C和C++——题目2
- 《Cracking the Coding Interview》——第13章:C和C++——题目3
- 《Cracking the Coding Interview》——第13章:C和C++——题目4
- 《Cracking the Coding Interview》——第1章:数组和字符串——题目1
- 《Cracking the Coding Interview》——第3章:栈和队列——题目7
- 《Cracking the Coding Interview》——第5章:位操作——题目6
- 《Cracking the Coding Interview》——第6章:智力题——题目3
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目5
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目4
- 《Cracking the Coding Interview》——第12章:测试——题目2
- 《Cracking the Coding Interview》——第14章:Java——题目6
- 《Cracking the Coding Interview》——第17章:普通题——题目2
- 《Cracking the Coding Interview》——第17章:普通题——题目6
- 《Cracking the Coding Interview》——第18章:难题——题目7