Search code examples
cvariablesspecifier

'static volatile' vs. 'static' vs. 'volatile' in C


What's the difference between using the variable specifiers static volatile combined? Or using one alone; like static or volatile in microcontroller programming?


Solution

  • static - in this case makes the variable visible only inside the current file. static object have static storage duration.

    volatile - it is information for the compiler that the object can be changed by something outside the normal execution path (for example, the interrupt routine) and guarantees that the variable will be read before any use and written after every change. volatile (which is a very common misunderstanding) does not guarantee anything else - no atomicity, no cache coherency, etc., etc.