Don Kinzer wrote: >... if there are any calls to other functions in > the code region of interest the compiler must > assume that any particular global variable > has been modified ... Good point. > ... unless it can determine conclusively otherwise. Which, I think, it generally can't for the C language. What I was getting at, as I'm sure you realized, is the common case of busy-waiting on a change in a global variable. Without the volatile modifier, the compiler will see no reason to repeatedly read the value as, while executing the busy-wait loop, it is impossible for the code that it is compiling to modify the value, either by a direct assignment or by an external function call. The volatile qualifier "tells" the compiler that "something else" might modify it while the loop is running. In other news, I am getting so fed up with this issue cropping up several times a year on various discussion groups that I am trying to prepare a definitive statement on when you should use the volatile qualifier and exactly what effect it has. I am hoping that, if I can get the appropriate peer reviews, people will reference this when the subject first arises. This might avoid the posting of yet more miss-information (which, as you point out, I am contributing to myself). Graham Davies ECROS Technology www.ecrostech.com
Message
Re: Volatile modifier
2012-04-17 by bayramdavies
Attachments
- No local attachments were found for this message.