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

前端 未结 3 1663
我在风中等你
我在风中等你 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:10

    This code volatile int *p = some_addr declares a pointer to a volatile int. The pointer itself is not volatile.

    In the unlikely event that you needed the pointer to be volatile as well as the int, you would need to use:

    volatile int * volatile p;
    

    I can't think of a situation where you would need to use that.

提交回复
热议问题