SWITCH CASE compile error
tdewild
Posts: 49
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: { }
}
0
Comments
{
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 suppose it is the same for next if you put it at the first place it may work.
But I have no idea why...
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 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.
Paul
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:
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.