Pelles C forum

C language => Beginner questions => Topic started by: x79 on February 26, 2015, 04:53:01 PM

Title: switch default 'Unrecognized statement'
Post by: x79 on February 26, 2015, 04:53:01 PM
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.
Title: Re: switch default 'Unrecognized statement'
Post by: frankie on February 26, 2015, 06:03:09 PM
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;
}
Title: Re: switch default 'Unrecognized statement'
Post by: x79 on February 26, 2015, 06:33:39 PM
ohhhhhhhhhh
ty
Title: Re: switch default 'Unrecognized statement'
Post by: Snowman on April 13, 2015, 10:34:36 AM
Thanks frankie and x79, I hit the same problem a few days back.
I guess we need to unlearn C++ a little bit.  8)