Solved What's the meaning of marking a whole class volatile?
-
#include <iostream> volatile class A{ public: void func1(); void func2(); void func3(); }; int main(){ return 0; }
Is there any difference between a non-volatile class and a volatile class?
-
Hi
Its kinda compiler dependant and also change a bit with c++ 11. ( to mean hardware access related)
Basically it tells the compiler it should not include the class/type in certain optimizations and
caching strategies.
That said, in 30 years of programming I have never used or seen a
volatile class in production code.
Only in cases with a misunderstanding of the keyword and used in inter-thread communication. -
I'm not aware of a volatile class. You can have volatile functions and volatile objects, but that specifier makes no sense for classes ...
-
yeah, I tend to think of volatile as a modifier for variables and not classes. Often ask in interviews whether the candidate knows what its for in embedded systems. Often misused, but important to understand the implications and when they are desirable: memory mapped register manipulation, etc.