Re: An Array of structs

2009-11-27 Thread Jens Alfke
On Nov 27, 2009, at 7:48 AM, Alastair Houghton wrote: > You *can* have non-constant elements in struct initialisers in C, *but* only > in a context where there is code that will execute at runtime. C++ eliminates most of these restrictions, btw. And you can make your code C++ simply by changin

Re: An Array of structs

2009-11-27 Thread Alastair Houghton
On 27 Nov 2009, at 13:30, Jeremy Pereira wrote: > You can't have non constant elements in struct initialisers, testy is not a > constant. The error message spells out exactly what the issue is. You *can* have non-constant elements in struct initialisers in C, *but* only in a context where ther

Re: An Array of structs

2009-11-27 Thread Jeremy Pereira
On 27 Nov 2009, at 11:35, John Love wrote: > > 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?

Re: An Array of structs

2009-11-27 Thread Graham Cox
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 gTe

An Array of structs

2009-11-27 Thread John Love
In my .h file, I have: typedef struct YearAmt { NSString *year; int amount; } YearAmt; extern NSString *testy; extern YearAmt gTest[]; In the corresponding .m file: NSString *testy = @"testy"; YearAmt gTest[] = {{testy, 10} /*, + others */}; I get "Initializer element i