I'm very confuse about volatile type variables. I understand you use it a lot when working with variables that changes alot and in embedded systems. Otherwise I don't understand why you use it. Can anyone give a more in depth explanation?
This is not strictly true, the volatile tag should be used when variables can change outside of direct program control irrespective of how often they change because any half decent compiler keeps track of the variables and optimises out or caches any variable that to its knowledge does not change. In embedded systems I/O ports and peripheral registers must be marked volatile as should global variables that are used by interrupt routines.I'm very confuse about volatile type variables. I understand you use it a lot when working with variables that changes alot and in embedded systems.
I suggest you take a look at this link for a brief but clear explanation of the volatile keyword. http://www.eetimes.com/discussion/beginner-s-corner/4023801/Introduction-to-the-Volatile-KeywordOtherwise I don't understand why you use it. Can anyone give a more in depth explanation?
Simple example. Look at the disassembly listing window for the effect of volatile on the code.I'm very confuse about volatile type variables. I understand you use it a lot when working with variables that changes alot and in embedded systems. Otherwise I don't understand why you use it. Can anyone give a more in depth explanation?
{ for(int i=0;i<255;i++); }
{ for(volatile int i=0;i<255;i++); }
{ volatile int i; for(i=0;i<255;i++); }
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
|
|
DMM count confusion | Test & Measurement | 6 | |
| F | PCB layout for oscillator - separated GND plane confusion | PCB Layout , EDA & Simulations | 49 | |
| I | BLDC Driver circuit confusion | General Electronics Chat | 5 | |
| C | Fuse Layout confusion | Power Electronics | 4 | |
| M | Differential pair - current flow confusion | Analog & Mixed-Signal Design | 8 |