Quoting Eric Weddington <[EMAIL PROTECTED]>:

<snip>

But he shouldn't _have_ to do that.  Bug in gcc?

Hmm.. point. Maybe a "missed optimization" type of bug. You could fill out a
GCC bug report. Feel free to put me on the CC list of the bug report so I
can track it.

This is not a "missed optimization". I hadn't time to test this yet, but if gcc compiles switch statements with volatile vars like that, it can give actual wrong results because the value of the variable may change *while* the if/else tree is being executed.

Imagine that your global var is switching between 0 and 4 and you have a switch statement that has cases 0, 1, 2, 3, 4, "default".

Lets assume the first test in the tree is (var > 2) and var=4 at this point, the code branches to a point where it tests for (var < 4) but before the test is executed the var changes (on an interrupt, or something) to 0. Now the test will give true, making the code execute the option for case 3. But the global variable never had that value at all!

I would need some time to build an actual test case to show this. Unfortunately, time is something that I don't have abundantly right now :(

--
Paulo Marques


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to