• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Declaring and initialization of C array.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Declaring and initialization of C array. (From: JAMES ROGERS <email@hidden>)
 >Re: Declaring and initialization of C array. (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: How to intercepting click on send in Mail.app
  • Next by Date: Re: Setting text field as first responder in an NSView
  • Previous by thread: Re: Declaring and initialization of C array.
  • Next by thread: Re: Declaring and initialization of C array.
  • Index(es):
    • Date
    • Thread