> -----Original Message-----
> From: 
> [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> org] On Behalf Of Christopher X. Candreva
> Sent: Tuesday, March 06, 2007 4:53 PM
> To: avr-gcc-list@nongnu.org
> Subject: Re: [avr-gcc-list] loop deleted using optimization
> 
> On Tue, 6 Mar 2007, alee wrote:
> 
> > Why does avr-gcc delete my empty "for" loops if I compile 
> with optimization
> > on?
> 
> Because that's what optimizaiton is.

Ok, that's the really terse answer. ;-)

For some more references, see the avr-libc user manual, FAQ #1, which talks
about using the keyword 'volatile'.

Essentially, when optimization is turned on, gcc is free to optimize away
code that literally, does nothing. If you want to keep those do-nothing
loops, then you need to declare the loop index variable as 'volatile', which
tells the compiler that accesss to that variable should not be optimized,
hence keeping the loop intact.

However, if your intent is to use the do-nothing loop as a delay, then you
need to take a closer look at the avr-libc user manual regarding the
<util/delay.h> header file. This provides a safer way to implement these
kinds of delays. Or use a hardware timer.

Eric Weddington



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to