Why is a point-to-volatile pointer, like “volatile int * p”, useful?

前端 未结 3 1674
我在风中等你
我在风中等你 2020-11-27 10:47

volatile is to tell the compiler not to optimize the reference, so that every read/write does not use the value stored in register but does a real memory access

3条回答
  •  星月不相逢
    2020-11-27 11:08

    On the usefulness of volatile: This is needed, if you need to check memory, which is modified by hardware like a serial interface controller. It has its application in the world of embedded systems, where you work very close to the hardware without any OS in-between.

提交回复
热议问题