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

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

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


From: stevech
Subject: [avr-gcc-list] Q: volatile member of structure?
Date: Sun, 10 Apr 2005 17:37:53 -0700

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)

   ;

 

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?


reply via email to

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