I have well tested code, developed with another compiler, that gives
trouble with mspgcc. My main program changes a global variable OK. However,
inside an interrupt routine, the variable appears to have a different value.
If I change the variable in that interrupt and return, the variable sometimes
reverts to its value before the interrupt occured. Is mspgcc buggy?
It is probably your code that is buggy, and not mspgcc. This catches a
lot of people out. GCC is a pretty smart compiler. It will seek out and remove
a lot of redundancy. However, this means you have to be quite precise about
what you ask it to do. You can be pretty sloppy writing for many compilers,
as they fails to optimise away a number of redundant things GCC will. If
something is volatile, you'd better make darned sure you declare it as such
with GCC, or you will have problems. This is not a GCC issue, but a good
compiler vs average compiler issue. If the main code keeps things in registers
for efficiency, the interrupt code may not see an up to date value when reading
from the copy in RAM. Similarly, if the interrupt code updates the copy in
RAM, the main code may ignore that value and use the one it is holding in a
register. A variable like this should be declared volatile, and this problem
will not occur.