I wrote a little state machine with the states being of an enum type. Sadly NXC does not accept the enum constants as case constants. May this be changed in a future release?
Seems to work for me using the enum constants. Your code (suitably modified to remove references to SR_Straight) compiles fine and the following also compiles and runs as expected:
physics-matt wrote:Seems to work for me using the enum constants. Your code (suitably modified to remove references to SR_Straight) compiles fine and the following also compiles and runs as expected:
No, it doesn't
The difference between your code and mine is that the enum is defined globally (your code) vs locally (my code). That is why my code does not work. That makes it even less understandable for me why my code does not work... I think there should be no difference between globally and locally defined enums.
Ciao marvin
Bye Marvin
- "I think you ought to know I'm feeling very depressed." - (Android Marvin in "The Hitchhiker's Guide to the Galaxy" by Douglas Adams, 1978)
I can confirm that it doesn't compile when the enum is declared locally while it do work if it is declared globally. (Using the newest release in the /test_release folder.) Furthermore, the error messages seems to return wrong line numbers.
The test release zip I uploaded this morning should fix the problem with local enum constants not working in switch case labels. Line number error reporting issues remain, however. Also, the way case labels are implemented is not exactly standard C. Prior to my changes yesterday you could get away with using a global variable name as a case label, for example. You used to be able to have duplicate case labels as well. Now I have some checks in place that enforce the rule that case labels must be constants and that they must be unique, but there are still some things you can do with case labels in C that you can't do in NXC and some things you can do in NXC that you can't do in C.
Please let me know if you encounter any problems with the support for switch statements and case labels in NXC.