• 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: An Array of structs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: An Array of structs


  • Subject: Re: An Array of structs
  • From: Graham Cox <email@hidden>
  • Date: Sat, 28 Nov 2009 00:18:28 +1100

On 27/11/2009, at 10:35 PM, John Love wrote:

> NSString *testy = @"testy";
> YearAmt gTest[] = {{testy, 10}  /*, + others */};
>
> I get "Initializer element is not constant. This pertains to the NSString* because if I directly substitute the following, no compile error happens:
> YearAmt gTest[] = {{@"testy", 10}
>
> What fundamental pertaining to C or C++ am I not getting?


The error tells you - the initialiser is not constant.

Sure, it's constant in the first line, but 'testy' is a variable, so you are trying to use a variable as a constant initializer in the second line. That isn't allowed.

If you think about how constant initializers in C actually work, at the machine code/assembler level, it should be clear why it isn't allowed.

--Graham

_______________________________________________

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: 
 >An Array of structs (From: John Love <email@hidden>)

  • Prev by Date: Re: Mount afp volume
  • Next by Date: Re: An Array of structs
  • Previous by thread: An Array of structs
  • Next by thread: Re: An Array of structs
  • Index(es):
    • Date
    • Thread