[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Is this a Bug??????
From: |
Jeff Dairiki |
Subject: |
Re: [avr-gcc-list] Is this a Bug?????? |
Date: |
Wed, 31 Jul 2002 06:53:52 -0700 |
On Wed, 31 Jul 2002 08:21:17 -0400
Lorne Gutz <address@hidden> wrote:
> Well then I figured out a work around. I declared
> timer_flag as volatile, and BOB's your uncle, it
> works.
Well, that's hardly a "work-around" :-)
That's precisely what the "volatile" keyword is for.
Without the "volatile", the C compiler thinks timer_flag is
a regular variable, and optimizes away any repeated loads
from it. Think about it: if "x" is a regular variable
and you have code which references "x" multiple times,
like:
var1 = x + 2;
var2 = x * 2;
var3 = x + var2;
you wouldn't want the compiler to generate assembly code
to load x from ram for each of those operations
(especially if those operations were in a loop).
"Volatile" is the only way the compiler has of knowing
when a variable might change value due to effects
outside of the "normal program flow".
avr-gcc-list at http://avr1.org