NO

Author Topic: switch default 'Unrecognized statement'  (Read 3072 times)

x79

  • Guest
switch default 'Unrecognized statement'
« on: February 26, 2015, 04:53:01 PM »
ok, I'm stumped  >:(

I get this error on the line just after default:
Code: [Select]
\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'.

Code: [Select]
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: switch default 'Unrecognized statement'
« Reply #1 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.
Code: [Select]
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

x79

  • Guest
Re: switch default 'Unrecognized statement'
« Reply #2 on: February 26, 2015, 06:33:39 PM »
ohhhhhhhhhh
ty

Snowman

  • Guest
Re: switch default 'Unrecognized statement'
« Reply #3 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)