Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为带有 Linux 环境的 ARM 编写程序。它不是一个低级程序,比如说应用程序级别
你能澄清一下有什么区别,
int iData;
对比
volatile int iData;
它有硬件特定的影响吗?
C 中 volatile 的存在是为了不自动缓存变量的值。它会告诉机器不要缓存这个变量的值。因此,每次遇到给定的 volatile 变量时,它都会从主内存中获取它的值。使用这种机制是因为任何时候操作系统或任何中断都可以修改该值。因此,使用 volatile 将帮助我们每次都重新访问该值。
阅读Wiki和此页面以获取更多说明