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

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

Re: [avr-gcc-list] Confusing volatile behaviour with 4.6.2


From: Paulo Marques
Subject: Re: [avr-gcc-list] Confusing volatile behaviour with 4.6.2
Date: Mon, 28 Nov 2011 12:38:05 +0000
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Andy Warner wrote:
> [...]
> Here is the USART0 rx interrupt handler that demonstrates the problem
> (apologies in advance, if gmail mangles this):
> 
> #define       SEARCHING (-2)
> #define       BREAK (-1)
> #define       MAX_DMX (512)
> 
> ISR(USART0_RX_vect)
> {
>       unsigned char status = UCSR0A;
>       unsigned char data = UDR0;
>       volatile static int slot = SEARCHING;

Does the problem still occur if you assign the variables later and not
at declaration time, i.e., something like:

        unsigned char status, data;
        volatile static int slot = SEARCHING;

        status = UCSR0A;
        data = UDR0;

I don't know from memory if the creation of local variables that are not
themselves volatile must respect their order. It might be the case that
the compiler is allowed to reorder the creation of the variables and
then it respects the volatile assignment by actually reading the memory
positions even if the values would be discarded later.

And why is the "slot" variable volatile? It seems there is no reason for
it and it makes the code a lot worse...

-- 
Paulo Marques - www.grupopie.com

"I used to be indecisive, but now I'm not so sure."



reply via email to

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