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

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

Re: [avr-gcc-list] Bug or bad optimization?


From: David Brown
Subject: Re: [avr-gcc-list] Bug or bad optimization?
Date: Thu, 3 Mar 2005 09:13:36 +0100

Klass,

This is completely wrong.  As a basic rule, if optomisation levels change
the functionality of the code, then your code is wrong (unless there is a
bug in the optomiser - unlikely, but possible in the "experimental"
optomisation passes).  The correct answer, without any doubt, is to use
"volatile" in the decleration of command, telling the compiler to re-read
the memory each run through the loop, which is exactly what you want.  If
your second "solution" works at all, it is by luck - the compiler would be
free to treat it exactly like the original while() loop.

For those that like urls:
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_volatile

mvh.,

David


>
> Hi,
>
> Had a similar problem. Try the following:
> Change: avr-gcc -S -mmcu=atmega128 -I. -gstabs   -Os -funsigned-char
> -funsigned-bitf
> To: avr-gcc -S -mmcu=atmega128 -I. -gstabs   -O0 -funsigned-char
> -funsigned-bitf
> (Switch off optimization)
>
> If you want to use optimization try this less elegant solution:
>
> RD_CMD:
> if(command == NULL) {
> goto RD_CMD;
> }
> // wait for command in uart getchar
>
> Regards,
> Klaas korterink
>






reply via email to

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