link error for 2+ static this()

Carlos Santander csantander619 at gmail.com
Wed Jun 7 12:36:40 PDT 2006


BCS escribió:
> This is the behavior I would expect. If there is some sort of technical 
> problem with multiple constructors than how can you have several static 
> class constructors? I would expect that whatever is done to sequence 
> these would be trivially expendable to module constructors.
> 
> I would like to see this ability. in some cases it would greatly improve 
> the readability of code.
> 
> Example:
> 
> <code>
> int[] someStaticDataSet;
> static this(){/* set up someStaticDataSet */ }
> 
> int useThis(int i){/* function uses someStaticDataSet */ return value;}
> 
> Object[int] someStaticAA;
> static this(){/* seeds someStaticAA */ }
> 
> bool PutThere(Object o, int i)
>     {/* function uses someStaticAA */ return false;}
> Object GetThat(int i)
>     {/* function uses someStaticDataSet */ return obj;}
> </code>
> 
> Lumping the two constructors together serves no purpose from a 
> readability standpoint.
> 
> Johan Granberg wrote:
>> Derek Parnell wrote:
>>
>>> It doesn't for me. I thought that meant that if one has more than one 
>>> static constructor in a module then they run in lexical order. For 
>>> example ....
>>> ...
>>> --Derek Parnell
>>> Melbourne, Australia
>>
>>
>> Ok in that case dmd and gdc have implemented this differently
>>
>> this code compiled with gdc-0.18
>>
>> //begin test.d
>> uint a=0,b=0;
>> static this()
>> {
>>     a=1;
>> }
>> static this()
>> {
>>     b=2;
>> }
>> void main()
>> {
>>     printf("%i, %i\n",a,b);
>> }
>> //end test.d
>> prints this
>> 1, 2

I would expect that, and I'd prefer for it to be allowed, but if it isn't going 
to work for whatever reason (in this case, linker error), better disallow and 
report it as an error as soon as possible.

I didn't know it worked with gdc. I think that's cool!

-- 
Carlos Santander Bernal



More information about the Digitalmars-d-bugs mailing list