DMD 1.014 release

Chris Nicholson-Sauls ibisbasenji at gmail.com
Fri Apr 27 14:41:10 PDT 2007


BCS wrote:
> Don Clugston wrote:
>>
>> In practice, you _can_ have initialized static AAs, provided they are 
>> read-only (which is probably the main time you want to supply 
>> initializers). The declaration syntax for a read-only AA slightly 
>> lacks syntactic sugar, but the syntax for usage is perfect:
>>
>> char[][uint] symTable() { return [2u:"he",4:"ho",6:"hi"]; }
>>
>> void main()
>> {
>>     for (int k=1; k<=6; ++k) {
>>         if ((k&1)==0) printf("%.*s\n", symTable[k]);
>>     }
>> }
>>
> 
> function call overhead on every use? Ouch!!
> 
> I'd rather go with
> 
> char[][uint] symTable; static this(){symTable=[2u:"he",4:"ho",6:"hi"];}

Which reminds me of an ancient enhancement request idea: allow the presence of /multiple/ 
static constructors within a scope (module or class), which are later concatenated into 
one function body by the compiler.  Then your above item becomes just one line, rather 
than a declaration in one place, and an initialization in the midst of a possibly longer 
function somewhere else entirely within the source file.  (I like keeping the number of 
lines that have to be hit for changes small... can you tell?  It makes it less likely I or 
someone else will make a silly mistake later.)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-announce mailing list