SWITCH CASE compile error
tdewild
Junior Member
Please explain why I get a compile error at the last DATA_EVENT.
//
Starting NetLinx Compile - Version[2.5.2.420] [10-06-2015 11:55:32]
// ERROR: (0): C10580: Internal Error: Major system error occurred during code generation
DATA_EVENT[dvDEVICE] // this works fine
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE '01': { }
CASE '02': { }
CASE '03': { }
CASE '04': { }
CASE '05': { }
CASE '06': { }
CASE '07': { }
CASE '08': { }
CASE '09': { }
CASE '10': { }
}
}
}
COMMAND: { }
}
DATA_EVENT[dvDEVICE] // this also works fine
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE 'n1': { }
CASE 'n2': { }
CASE 'n3': { }
CASE 'n4': { }
CASE 'n5': { }
CASE 'n6': { }
CASE 'n7': { }
CASE 'n8': { }
CASE 'n9': { }
CASE 'n10': { }
}
}
}
COMMAND: { }
}
DATA_EVENT[dvDEVICE] // compile error!!!
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
CASE '10': { } // remove this to remove the error
}
}
}
COMMAND: { }
}
//
Starting NetLinx Compile - Version[2.5.2.420] [10-06-2015 11:55:32]
// ERROR: (0): C10580: Internal Error: Major system error occurred during code generation
DATA_EVENT[dvDEVICE] // this works fine
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE '01': { }
CASE '02': { }
CASE '03': { }
CASE '04': { }
CASE '05': { }
CASE '06': { }
CASE '07': { }
CASE '08': { }
CASE '09': { }
CASE '10': { }
}
}
}
COMMAND: { }
}
DATA_EVENT[dvDEVICE] // this also works fine
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE 'n1': { }
CASE 'n2': { }
CASE 'n3': { }
CASE 'n4': { }
CASE 'n5': { }
CASE 'n6': { }
CASE 'n7': { }
CASE 'n8': { }
CASE 'n9': { }
CASE 'n10': { }
}
}
}
COMMAND: { }
}
DATA_EVENT[dvDEVICE] // compile error!!!
{
ONLINE: { }
STRING:
{
IF(LENGTH_ARRAY(DATA.TEXT)>0)
{
STACK_VAR CHAR cCMD[20];
cCMD = DATA.TEXT;
SWITCH(cCMD)
{
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
CASE '10': { } // remove this to remove the error
}
}
}
COMMAND: { }
}
Comments
-
Did you try to put case '10' at the first place ?
-
SWITCH(cCMD) // this works fine
{
CASE '10': { }
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
}
SWITCH(cCMD) // this works fine
{
CASE '10': { }
CASE '11': { }
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
}
SWITCH(cCMD) // this works fine
{
CASE '01': { }
CASE '02': { }
CASE '03': { }
CASE '04': { }
CASE '05': { }
CASE '06': { }
CASE '07': { }
CASE '08': { }
CASE '09': { }
CASE 'NEXT': { }
}
SWITCH(cCMD) // SAME COMPILE ERROR
{
CASE '10': { }
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
CASE 'NEXT': { }
}
SWITCH(cCMD) // SAME COMPILE ERROR
{
CASE '1': { }
CASE '2': { }
CASE '3': { }
CASE '4': { }
CASE '5': { }
CASE '6': { }
CASE '7': { }
CASE '8': { }
CASE '9': { }
CASE 'NEXT': { }
} -
I have already seen this issue, just have to guess in which order to set the case in order it works fine.
I suppose it is the same for next if you put it at the first place it may work.
But I have no idea why...
-
Strange question but If you create constant with your value does it compiled?
-
There is a known issue with single char SWITCH/CASE.
If you put the '10' (2 chars) and 'NEXT' (4 chars) first it will work, but not if you put one of them after a single char CASE. I don't know why - it's caught me out before when trying to trap both '0' and 'false'.
Simon -
I did not know this, no Tech Note about it.
I was lucky it happend in a small piece of code, easy to find what happend but not why.
Modify the code so it uses a SELECT/ACTIVE statement instead could be the answer from tech support
So be ware of a single char in a SWITCH/CASE, a integer will work fine.
CASE closed.
-
if you place the case with the larger length first in you switch()case, it will compile.
DATA_EVENT[dvDEVICE] // compile error!!! { ONLINE: { } STRING: { IF(LENGTH_ARRAY(DATA.TEXT)>0) { STACK_VAR CHAR cCMD[20]; cCMD = DATA.TEXT; SWITCH(cCMD) { case 'NEXT':{} CASE '10': { } // remove this to remove the error CASE '1': { } CASE '2': { } CASE '3': { } CASE '4': { } CASE '5': { } CASE '6': { } CASE '7': { } CASE '8': { } CASE '9': { } //case ten:{} } } } COMMAND: { } } -
Another switch statement oddity, is putting the default case somewhere else rather than at the end. You should be able to do this, and it does compile, but doesn't work as expected.
Paul -
I would expect it to ignore any cases below the default. I view it as an elevator that always starts at the top floor, the elevator goes down and you have to get off at the 1st open door/floor and "default:" is a door that can't be closed so you have to get off when you get to it. If you put the default at the top of the building you'll never get below it unless you take the stairs.Another switch statement oddity, is putting the default case somewhere else rather than at the end. You should be able to do this, and it does compile, but doesn't work as expected.
Paul -
I would expect it to ignore any cases below the default. I view it as an elevator that always starts at the top floor, the elevator goes down and you have to get off at the 1st open door/floor and "default:" is a door that can't be closed so you have to get off when you get to it. If you put the default at the top of the building you'll never get below it unless you take the stairs.
Well I think of it such that default is the case that is executed when all cases are evaluated but none match. Where it is in the statement shouldn't really matter. Its called the default case, not the 'final' case. In fact, in some cases (no pun intended), I would prefer it to be first case since the default will be the most commonly executed case. IE:switch(iButton) { case default: { beep() } case 666: { summonSatan() } } -
My understanding is that a switch case statement is internally similar to if, else if & else.
Therefore, putting default first is like putting else first. -
My understanding is that a switch case statement is internally similar to if, else if & else.
Therefore, putting default first is like putting else first.
I don't think so. Putting an else first doesn't compile, obviously. But the compiler allows you to put the default case anywhere in a switch statement. If its not going to work at runtime, then the compiler shouldn't allow it. In other languages it works fine in any position. Besides, how the compiler wants to implement it should have no bearing on if it works as intended. There really is no reason that these two button events should have different results yet compile without issue, no warnings, no errors, etc. The help file states the default case has to come last, yet the compiler doesn't enforce it.button_event[vdvTest, 1] { push: { stack_var integer i switch(i) { default:{} case 1:{} } } button_event[vdvTest, 1] { push: { stack_var integer i switch(i) { case 1:{} default:{} } }
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums

