On 2006-12-10, Steve Underwood <[email protected]> wrote:

>>>>I'm having trouble with mspgcc version 3.2.3 accessing a variable
>>>>that's been declared as volatile twice, when my code refers to it
>>>>only once.
>>>>      
>>>>
>>[...]
>>
>>>>Note that the code is accessing the switch variable twice, in
>>>>the cmp instruction at 0xfc46 and in the mov instruction at
>>>>0xfc4c. This is fairly problematic, since when I switch on the
>>>>value of I2CIV in my I2C interrupt function I miss a large
>>>>number of interrupts!
>>>>
>>>I'm guessing you weren't optimizing your example code
>>
>>That's moot.  The generated code is incorrect[1].  Compilers
>>are not permitted to generate incorrect code regardless of
>>optimization settings.
>>
>>[1] Unless I misunderstood the C standard's requirement for
>>    the implementation of volatile variables.
>
> If you turn on optimisation, this problem goes away. As you
> say, that is a moot point if the compiler has produced wrong
> code. I don't know what the C spec actually says, though,

I read it once, but it's a little hard to follow.

> and I don't have a full copy of it to hand. Can anyone quote
> exactly what C99 says on this subject. I suspect GCC has done
> something compliant, but useless.

I'm sure asking on comp.lang.c would get a correct answer.

-- 
Grant Edwards                   grante             Yow!  Clear the
                                  at               laundromat!! This
                               visi.com            whirl-o-matic just had a
                                                   nuclear meltdown!!


Reply via email to