volatile int for frame count

Post Reply
LeRodeur
Posts: 13
Joined: Tue Jul 31, 2012 2:36 pm

volatile int for frame count

Post by LeRodeur » Sat Jul 26, 2014 8:00 pm

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

elhobbs
Posts: 355
Joined: Thu Jul 02, 2009 1:19 pm

Re: volatile int for frame count

Post by elhobbs » Sun Jul 27, 2014 2:36 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests