Answer by Joey L. Q. for Why is volatile needed in C?
Volatile is often misunderstood as "disabling optimizations," synchronizing access to a variable, or generating memory fences. None are entirely the case. All it does is disable any compiler...
View ArticleAnswer by Siddharth for Why is volatile needed in C?
As rightly suggested by many here, the volatile keyword's popular use is to skip the optimisation of the volatile variable.The best advantage that comes to mind, and worth mentioning after reading...
View ArticleAnswer by rajeshsam for Why is volatile needed in C?
In simple terms, it tells the compiler not to do any optimisation on a particular variable. Variables which are mapped to device register are modified indirectly by the device. In this case, volatile...
View ArticleAnswer by supercat for Why is volatile needed in C?
In the language designed by Dennis Ritchie, every access to any object, other than automatic objects whose address had not been taken, would behave as though it computed the address of the object and...
View ArticleAnswer by Oliver for Why is volatile needed in C?
In my opinion, you should not expect too much from volatile. To illustrate, look at the example in Nils Pipenbrinck's highly-voted answer.I would say, his example is not suitable for volatile. volatile...
View ArticleAnswer by Venkatakrishna Kalepalli for Why is volatile needed in C?
My simple explanation is:In some scenarios, based on the logic or code, the compiler will do optimisation of variables which it thinks do not change. The volatile keyword prevents a variable being...
View ArticleAnswer by coanor for Why is volatile needed in C?
Wikipedia says everything about volatile:volatile (computer programming)And the Linux kernel's documentation also makes a excellent note about volatile:Why the "volatile" type class should not be used
View ArticleAnswer by Alexey Frunze for Why is volatile needed in C?
I'll mention another scenario where volatiles are important.Suppose you memory-map a file for faster I/O and that file can change behind the scenes (e.g. the file is not on your local hard drive, but...
View ArticleAnswer by Neo Cambell for Why is volatile needed in C?
There are two uses. These are specially used more often in embedded development.The compiler will not optimise the functions that use variables that are defined with the volatile keywordVolatile is...
View ArticleAnswer by Structure padding for Why is volatile needed in C?
volatile means the storage is likely to change at any time and be changed by something outside the control of the user program.This means that if you reference the variable, the program should always...
View ArticleAnswer by Robert S. Barnes for Why is volatile needed in C?
See this article by Andrei Alexandrescu, "volatile - Multithreaded Programmer's Best Friend"The volatile keyword wasdevised to prevent compileroptimizations that might render codeincorrect in the...
View ArticleAnswer by Alexandre C. for Why is volatile needed in C?
A marginal use for volatile is the following. Say you want to compute the numerical derivative of a function f :double der_f(double x){ static const double h = 1e-3; return (f(x + h) - f(x)) / h;}The...
View ArticleAnswer by venu for Why is volatile needed in C?
It does not allow the compiler to automatically change values of variables. A volatile variable is for dynamic use.
View ArticleAnswer by CesarB for Why is volatile needed in C?
Another use for volatile is signal handlers. If you have code like this:int quit = 0;while (!quit){ /* very small loop which is completely visible to the compiler */}The compiler is allowed to notice...
View ArticleAnswer by Diomidis Spinellis for Why is volatile needed in C?
Volatile is also useful, when you want to force the compiler not to optimize a specific code sequence (e.g. for writing a micro-benchmark).
View ArticleAnswer by Ori Pessach for Why is volatile needed in C?
A volatile can be changed from outside the compiled code (for example, a program may map a volatile variable to a memory mapped register).The compiler won't apply certain optimizations to code that...
View ArticleAnswer by Nils Pipenbrinck for Why is volatile needed in C?
volatile tells the compiler not to optimize anything that has to do with the volatile variable.There are at least three common reasons to use it, all involving situations where the value of the...
View ArticleAnswer by Manoj Doubts for Why is volatile needed in C?
volatile in C actually came into existence for the purpose of not caching the values of the variable automatically. It will tell the compiler not to cache the value of this variable. So it will...
View ArticleAnswer by C. K. Young for Why is volatile needed in C?
volatile tells the compiler that your variable may be changed by other means, than the code that is accessing it. e.g., it may be a I/O-mapped memory location. If this is not specified in such cases,...
View ArticleWhy is volatile needed in C?
Why is volatile needed in C? What is it used for? What will it do?
View Article
More Pages to Explore .....