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

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

Re: [avr-gcc-list] Q: volatile member of structure?


From: Ormund Williams
Subject: Re: [avr-gcc-list] Q: volatile member of structure?
Date: 11 Apr 2005 02:01:33 -0400

On Sun, 2005-04-10 at 20:37, stevech wrote:
> Is this a minor bug?
> 
>  
> 
> Some_structure contains 8 bit member - I'll call it "m" here.
> 
> That structure has a typedef and an instance in global memory - I'll
> call it "t" here.
> 
>  
> 
> So t.m refers to that byte.
> 
>  
> 
> Now since my interrupt routine and my non-interrupt code both access
> t.m, I coded this, in my non-interrupt code:
> 
>  
> 
> x = t.m;
> 
> while (x == (volatile unsigned char) t.m) 
> 
You need to declare t.m as volatile when it is created. t.m can be
changed by the interrupt routine at any time not just when you are
comparing it to x. 
>    ;
> 
>  
> 
> But the resultant assembly code shows that t.m is not re-fetched from
> memory in the while loop. The while loop just compares two registers
> in a two instruction loop.  This is with the default optimization
> setting. If I turn off optimization, t.m is indeed repeatedly fetched
> from memory.
> 
>  
> 
> So, shouldn't the cast force the compiler to treat t.m as a volatile?
> Did I code the cast correctly?
> 
>  
> 
> A cure, I suppose, is to declare the typedef'd structure or its
> instance as volatile?
> 
> 
> 
> ______________________________________________________________________
> 
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
-- 
Ormund Williams <address@hidden>
ORMLAB





reply via email to

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