Programming: Create a Global Variable that will Not be Optimized Out (Static Volatile)

When creating a global variable, especially when the variable will be used in an ISR (Interrupt Service Routine), this global variable may be eliminated by the compiler (optimized out). To force this variable to be used and not optimized out, declare the variable with its type and 'static volatile' and then the variable.



Example: type static volatile variable = value; int static volatile InchesOfHg = 0;
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.