Re: An Array of structs
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