answersLogoWhite

0

The volatile specifier informs the compiler that an object could be modified by something that is external to the thread of execution; something that is not part of the program. For instance, when reading a hardware clock, you would rightly expect the value of that clock to change from one read to the next. But from the compiler's perspective, the clock remains constant because your code does not alter it between reads and is unaware of any external code that controls its value. Therefore the compiler will (rightly) optimise away what it believes to be redundant read operations which could easily break the semantics of your code.

By declaring an object volatile (even a constant object), you inform the compiler that the object may change between successive read or write operations and that all redundancy optimisations must not be applied to any code that uses that object.

Although often used as a method of synchronisation between concurrent threads within the same thread of execution that share the same object, you must not use it for this purpose. C++ provides very specific mechanisms for this purpose, such as an atomic, a mutex or a condition_variable. The volatile specifier must only be used when writing low-level code that deals directly with hardware, such as when writing device driver and embedded system software.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What are the Merits and demerits of exception handling in c plus plus?

Are mala cha pahije disadvantages.. ani tumhi mala vichartat.. ask to scientist....


Can you control ports through c plus plus?

Yes. If the ports are memory mapped, then you simply need a pointer to that address, and you need to declare the pointer as volatile. If they are I/O mapped, then you need to create an _asm{} block.


What is c keywords?

switch, volatile, break, etc


How do you get merits on Toontown?

To earn merits you must have your sellbot suit and defeat sellbot cogs in battles. Easiest way to earn merits is factory. Try to do factories with invasion because it will give 776 merits and normally is 388 merits. Getting double merits is a good way to get ready for vp faster plus when yoy got to do 5500 merits which is 7 long invasion factories. Hope this helps :) By: Toontown Answer Expert


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What are the boiling points of volatile compounds?

The boiling points of volatile compounds will vary depending on the specific compound. Generally, volatile compounds have low boiling points, typically below 100°C. Some examples of volatile compounds with low boiling points include ethanol (78.3°C), acetone (56°C), and diethyl ether (34.6°C).


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


Explain volatile keyword In C?

http://www.netrino.com/node/80 Good Article explaining, volatile keyword in detail. -- Pradeep Reddy


Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.