Re: Declaring and initialization of C array.
Re: Declaring and initialization of C array.
- Subject: Re: Declaring and initialization of C array.
- From: Wim Lewis <email@hidden>
- Date: Wed, 01 Jun 2011 10:46:29 -0700
On 1 Jun 2011, at 8:17 AM, Graham Cox wrote:
> On 02/06/2011, at 1:12 AM, JAMES ROGERS wrote:
>> K&R says to declare and initialize an array in C:
>>
>> int myArray[2] = {1,2};
>> ArrayTestAppDelegate.h:14: error: expected ':', ',', ';', '}' or '__attribute__' before '=' token
If I copy and paste that line into a file and compile it, it compiles file.
My guess is that you're missing a semicolon on an earlier line of the header, and the compiler is trying to parse 'int myArray[2]...' as part of an earlier declaration.
> On 02/06/2011, at 1:12 AM, JAMES ROGERS wrote:
>> If the above is entered into the .h file
>
> That's because a .h file is the HEADER.
No. It's true that it should be in a .c file, but that is not the reason that James is having a problem. The compiler actually doesn't care whether code came from a header or not--- you shouldn't do it unless you know what you're doing, because it is confusing and awkward, but there are legitimate reasons to do so.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden