Page 1 of 1

volatile int for frame count

Posted: Sat Jul 26, 2014 8:00 pm
by LeRodeur
Hi,
I just happened to see that the frame variable in the hello_world was defined as a volatile int.
Is there any specific reason?
I mean, would the optimizations pose problems on this specific variable? If yes why?
Thanks

Re: volatile int for frame count

Posted: Sun Jul 27, 2014 2:36 am
by elhobbs
since this variable is updated in an irq handler it needs to be read from memory each time in the main loop. without the volatile declaration it would most likely be read once into a register and the updates would be never be seen.