我看到它是可能的,但我不理解它的兴趣。
发布于 2010-06-13 06:49:39
const和volatile是正交的。
const表示数据是只读的。
volatile意味着变量可能会因为外部原因而改变,因此每次引用变量时,编译器都需要从内存中读取该变量。
因此,删除const允许您编写一个只读位置(代码必须具有一些特殊知识,该位置实际上是可修改的)。你不应该删除volatile来写它,因为你可能会导致未定义的行为(由于7.1.5.1/7 - If an attempt is made to refer to an object defined with a volatile-qualified type through the use of an lvalue with a non-volatile-qualified type, the program behaviour is undefined.)
https://stackoverflow.com/questions/3030382
复制相似问题