avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] loop deleted using optimization


From: Eric Weddington
Subject: RE: [avr-gcc-list] loop deleted using optimization
Date: Tue, 06 Mar 2007 19:12:55 -0700

 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Christopher X. Candreva
> Sent: Tuesday, March 06, 2007 4:53 PM
> To: address@hidden
> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]