• 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: Vyacheslav Karamov <email@hidden>
  • Date: Thu, 02 Jun 2011 10:36:17 +0300

I agree with you, but I guess he missed semicolon just before an array declaration because he got *compiler* error, not linker!

Correct declaration could be of two forms:
1) In header file
static int a[2] = {1,2};
or
static int a[] = {1,2};

2) In header file
extern int a[2];

In *.m file:
int a[2] = {1,2};

01-Jun-11 19:14, Ron Hunsinger пишет:

The problem is that while globals can be declared in as many compilation units as you wish, they must be defined in only one. That means that a definition cannot appear in a file that's #included into multiple compilation units.

It would be perfectly fine to put that initializer in a .h file, as long as the .h file is #included into only one .c file. That's not how we normally use .h files, though, because it would make the name visible in only the one compilation unit that included it. The whole point of having separate .h and .c files is to work around the "declared in multiple units: OK, defined in multiple units: BAD" limitation, without giving up the safety of "declared in multiple source files: BAD"._______________________________________________

_______________________________________________

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>)
 >Re: Declaring and initialization of C array. (From: Ron Hunsinger <email@hidden>)

  • Prev by Date: Re: Notify With Parameters
  • Next by Date: Re: Code style (was: Notify With Parameters)
  • Previous by thread: Re: Declaring and initialization of C array.
  • Next by thread: Re: How to intercepting click on send in Mail.app
  • Index(es):
    • Date
    • Thread