Friday, June 10, 2011

EFI interview - 4

这回是以前一个在Qualcomm面试中问过的问题,关于volatile关键字的作用。我跟面试官谈了一下,不过他说我说的原理是对的,但没有说出volatile的用法的intention所在,真是个傻逼。

再复习一下
---
在K&R的Bible的附录A.8.2里面,提到了这么一段:
The purpose of volatile is to force an implementation to suppress optimization that could otherwise occur. For example, for a machine with memory-mapped input/output, a pointer to a device register might be declared as a pointer to volatile, in order to prevent the compiler from removing apparently redundant references through the pointer.

另外,相关的资料也可参见下面的link:
http://en.wikibooks.org/wiki/Embedded_Systems/C_Programming
http://vault.embedded.com/story/OEG20010615S0107
http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html

No comments:

Post a Comment