[Top][All Lists]

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

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

From: Dmitry K.
Subject: Re: [avr-gcc-list] Q: volatile member of structure?
Date: Mon, 11 Apr 2005 17:22:07 +1100
User-agent: KMail/1.5

On Monday 11 April 2005 11:37, stevech wrote:
> 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?

Cast operation is not change declaration. It is only a conversion
function. So, '(volatile)t.m' is dummy.

To force a fetch from memory, you must write:

   while (x == *(volatile unsigned char *) & t.m)


reply via email to

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