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

R1S8K picture R1S8K · Sep 2, 2017 · Viewed 32.1k times · Source

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

Answer

0___________ picture 0___________ · Sep 2, 2017

static - in this case makes the variable visible only inside the current file

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.