Re: Compiler Error (expected expression before 'NSArray')
Re: Compiler Error (expected expression before 'NSArray')
- Subject: Re: Compiler Error (expected expression before 'NSArray')
- From: Jeremy Pereira <email@hidden>
- Date: Mon, 15 Feb 2010 16:24:26 +0000
On 15 Feb 2010, at 16:08, jeremy wrote:
> Why does the following code cause the compiler error "expected expression before 'NSArray'"?
C99 syntax does not allow you to put a variable declaration straight after a case label.
>
> ----
> int i = 0;
> switch (i) {
> case 0:
> NSArray *results;
> break;
> default:
> break;
> }
> ----
>
> Why does the following produce no compiler error, with the addition of curly braces?
Because you have created a new block after the case label (which is legal syntax) and it is legal to put a declaration at the start of a block
>
> ----
> int i = 0;
> switch (i) {
> case 0:
> {
> NSArray *results;
> }
> break;
> default:
> break;
> }
> ----
>
> If I comment out the curly braces, the compiler once again reports the error "expected expression before 'NSArray'". Where is the problem expression? Why do I get the compiler error?
This is syntactically identical to your first piece of code. Of course it's going to error.
>
> ----
> int i = 0;
> switch (i) {
> case 0:
> // {
> NSArray *results;
> // }
> break;
> default:
> break;
> }
> ----
>
> Using
> XCode 3.2.1
> Active SDK: Max OS 10.6 (Base SDK)
> Active Architecture: x86_64
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden