[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AW: [avr-gcc-list] gcc bug
From: |
Andreas Trenkwalder |
Subject: |
AW: [avr-gcc-list] gcc bug |
Date: |
Thu, 24 Jun 2004 09:44:42 +0200 |
Hi!
> struct smotor { uint16_t count; } motor;
>
> main() {
> // code to set up a timer which sets up a
> // signal handler for SIG_OVERFLOW0.
> ...
> func();
> // never returns from func().
> }
>
> func() {
> motor.count = 10;
> while(motor.count > 0) {
> ;
> }
> }
>
> signal(SIG_OVERFLOW0) {
> if (motor.count) {
> motor.count--;
> }
> }
>
>
Declare the variable motor as 'volatile'!
This indicates that a variable may be changed in a way which is
unpredictable by analysing the normal program flow (such as variable which
may be changed by an interrupt handler). This behavior is also explained in
the AVR-libc FAQ [1].
Regards,
Andreas
[1] http://www.nongnu.org/avr-libc/user-manual/FAQ.html