Quote:
Originally Posted by That Don Guy
For some reason, when I try this:
Code:
switch (n)
{
case 1:
bool YesOrNo = YES;
...
}
I get an "Expected expression before _Bool" error.
However, if I do this:
Code:
switch (n)
{
case 1:
someExistingVariable = 0;
bool YesOrNo = YES;
...
}
then it works.
Is there a reason for this seemingly odd behavior?
EDIT: I have discovered that it applies to all types (not just bool)
-- Don
|
This is a known issue with this version of C. The compiler doesn't like variable declarations on the first line of a case statement, for some reason. I'm not sure if the C specification dictates that this be an error, or it's a problem with the implementation, or what, but it is what it is.
The simplest way to avoid getting the error is to wrap everything in your case statements with curly braces, like this:
Code:
switch (n)
{
case 1:
{
bool YesOrNo = YES;
...
break;
}
}