Where all to use volatile keyword in C

前端 未结 5 1670
余生分开走
余生分开走 2021-01-20 04:37

I know volatile keyword prevents compiler from optimizing a variable and read it from memory whenever it is read. Apart from memory mapped registers, what are all the situat

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-20 05:10

    Besides extensions such as memory mapped devices, in standard C volatile has two use cases: interaction with signal handlers and modification of objects across usage of setjmp/longjmp. Both are case were there is unusual flow of control that an optimizer may not be aware of.

提交回复
热议问题