volatile用法
2013-10-13 00:44
267 查看
1. volatile 修饰基础变量,意为该变量拒绝cache优化,每次存取直接访问内存;
2. volatile 修饰函数前,则意为无需为调用函数保存返回地址;
3. volatile 如果在后面同时该函数为类方法,那么当该类对应的实例对象为volatile时,该方法可以被调用,volatile对象是不能调用非volatile方法的,例如:
class A { volatile int m ; public: bool is_ok() volatile { if (m) return true; else return false; } bool is_not_ok() { if (m) return false; else return true; } }; int main() { volatile A obj; obj.is_ok();// it is ok obj.is_not_ok();// it will have compile error "error: no matching function for call to 'A::is_not_ok() volatile'" }
相关文章推荐
- 了解 volatile 的用法
- C中的volatile用法
- C中的volatile用法
- volatile 用法以及大家遇到的问题
- C语言中volatile的用法
- C中的volatile用法
- volatile的用法
- 多线程中关键字Volatile的用法及作用
- __asm__ __volatile__内嵌汇编用法简述
- C中的volatile的用法
- register、volatile、restrict 三关键字的用法
- C++中volatile的用法
- C语言中的volatile用法
- c语言关键字volatile的用法3
- C中的volatile用法
- const、volatile、mutable的用法
- const 和volatile的用法
- C中的volatile用法
- const、volatile、mutable的用法
- __asm__ __volatile__内嵌汇编用法简述