Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-28-2010, 02:27 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Benicia, CA
Age: 50
Posts: 152
That Don Guy is on a distinguished road
Default Can't declare a "bool" variable within a select?

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

Last edited by That Don Guy; 12-28-2010 at 02:45 PM.
That Don Guy is offline   Reply With Quote
Old 12-28-2010, 06:32 PM   #2 (permalink)
Pro. Game Developer
iPhone Dev SDK Supporter
 
Join Date: Feb 2009
Location: żLa Islas Hermosas?
Posts: 2,176
Kalimba is on a distinguished road
Default

Quote:
Originally Posted by That Don Guy View Post
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;
    }
}
__________________
~~ Word Flurry ~~ App Store / Website / Facebook
Kalimba is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 480
15 members and 465 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0