调试 RT-Thread 时,我的代码怎么“被优化”了? | 技术集结
以下是关于volatile关键的外文描述:
By declaring an object volatile, the compiler is informed that the value of the object can change beyond the compiler’s control. The compiler must also assume that any accesses can have side effects—thus all accesses to the volatile object must be preserved.
There are three main reasons for declaring an object volatile:
- Shared access; the object is shared between several tasks in a multitasking environment
- Trigger access; as for a memory-mapped SFR where the fact that an access occurshas an effect
- Modified access; where the contents of the object can change in ways not known tothe compiler.