Volatile variable

前端 未结 6 1520
梦谈多话
梦谈多话 2020-12-25 15:12

Where is a volatile variable stored in the program memory(in which section) ?

6条回答
  •  一整个雨季
    2020-12-25 15:37

    In C volatile just tells the compiler - "You don't have enough knowledge to assume the value of this variable hasn't changed". There is no "section" eg BSS, CSS for it.

    Consider it a flag to the compiler to prevent certain types of optimisations. Its very handy in embedded programming, where memory at a certain address may "change" due to a hardware device input.

    Here's a good explanation: http://www.embedded.com/columns/programmingpointers/174300478?_requestid=137658

提交回复
热议问题