3 ms·
I use volatile on memory mapped input ports. It tells the compiler that if I am reading twice from this address without writing to it in between, don't optimize
by droithomme 7y ago
I use volatile on memory mapped input ports. It tells the compiler that if I am reading twice from this address without writing to it in between, don't optimize out the subsequent reads because this is not a memory location whose contents are under the control of the program. If the compiler ignores this, the software most certainly will break and break hard. For some applications the results will be crashed vehicles, runaway industrial processes, and dead people. Compilers are not free to ignore volatile and it is not a suggestion to the compiler, it is a directive which must be obeyed. Compilers that don't do this are broken compilers.
- jcelerier 7y agothankfully that is not what is deprecated. what is deprecated is marking stuff like class methods being volatile : class foo { void i_am_deprecated() volatile; void i_am_also_deprecated(volatile int); void i_am_not(volatile char*); }; Did you ever have a use for this ?
- droithomme 7y agoThanks, not the first two. I'm not sure what volatile pass by value means and did not know that that was ever a thing. The third one, yeah, I use that, and you have it marked as non deprecated, so that's good.