switch default 'Unrecognized statement'

Started by x79, February 26, 2015, 04:53:01 PM

Previous topic - Next topic

x79

ok, I'm stumped  >:(

I get this error on the line just after default:
\Projects\test\main.c(76): error #2157: Unrecognized statement.
\Projects\test\main.c(76): error #2001: Syntax error: expected ';' but found 'iMove'.
\Projects\test\main.c(76): error #2048: Undeclared identifier 'iMove'.


switch (iCliLen)
{
case 1 :
wmemcpy(sArgPtr, sArgPtr+1, iLen2);
sArgPtr[0] = sCli[0];
break;
case 2 :
wmemcpy(sArgPtr, sCli, 2);
break;
default :
// What is wrong with this???
int iMove = iCliLen-2;
for (int x=iLen2+1+iMove; x>=iMove+1; x--)
sArgPtr[x] = sArgPtr[x-iMove];
break;
}


Project was created/written with v8 RC7 but I added the source to a blank project with v7 and attached that one. Same error either way.

frankie

Switch doesn't allow local declarations in cases without creating a block scope. Enclose your case code in braces and it will work.

default :
{
int iMove = iCliLen-2;
for (int x=iLen2+1+iMove; x>=iMove+1; x--)
sArgPtr[x] = sArgPtr[x-iMove];
break;
}
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide


Snowman

Thanks frankie and x79, I hit the same problem a few days back.
I guess we need to unlearn C++ a little bit.  8)