Grant Edwards wrote:
On 2006-12-09, David Dyck <[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, 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.
Regards,
Steve