According to cppreference, most uses of the volatile
keyword are to be deprecated in C++20. What is the disadvantage of volatile
? And what is the alternative solution when not using volatile
?
According to cppreference, most uses of the volatile
keyword are to be deprecated in C++20. What is the disadvantage of volatile
? And what is the alternative solution when not using volatile
?
There's a good talk by the C++ committee language evolution chair on why.
Brief summary, many of the places that volatile
is being removed from didn't have any understandable meaning and just caused confusion.
Some examples from the talk:
+=
a single/atomic instruction? How about ++
?compare_exchange
? What if it fails?void foo(int volatile n)
mean? or int volatile foo()
*vp;
do a load? (This has changed twice in the standard.)