2 ms·
What is an example of using volatile that the compiler can conclude is pointless? I find it hard to imagine non-contrived examples, since the point of volatile
by FartyMcFarter 7y ago
What is an example of using volatile that the compiler can conclude is pointless?
I find it hard to imagine non-contrived examples, since the point of volatile is to tell the compiler "don't assume or optimize any access to this variable - entities unknown to you can read/write it at any moment".
If the compiler can't make such assumptions, how can it diagnose whether there's a point or not?
- antisemiotic 7y agoThere are some examples mentioned in the link, like volatile non-pointer non-reference variables. This can't be used for the real purpose of volatile (memory-mapped IO, etc) and could only result from someone confusing volatile with atomic, so it's safe to deprecate these.