Interrupt variable exceeds volatile long's 8bit size

IIRC, the volatile keyword originated in memory-mapped I/O systems where an I/O register would be in the RAM memory space, so a digital pin could be changed by an external sensor, and volatile was used to tell the compiler that something it didn't know about could change the value, so it should not be removed from the code.

In the interrupt case, the compiler certainly knows that the variable is being updated, but it may not "see" that the interrupt service routine is called since it isn't responsible for updating the interrupt vector table to point to that ISR (I think that's the job of the linker?).

1 Like