Thread overview | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 01, 2006 link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
this gives a link error with somthing about duplicate symbols. <code> void main(){} static this(){} static this(){} <\code> DMD 0.158(?) linux not tried on win. |
June 02, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS Attachments: | BCS schrieb am 2006-06-01: > this gives a link error with somthing about duplicate symbols. > ><code> > void main(){} > static this(){} > static this(){} ><\code> > > DMD 0.158(?) linux > > not tried on win. Added to DStress as http://dstress.kuehne.cn/nocompile/t/this_12_A.d Thomas |
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> this gives a link error with somthing about duplicate symbols.
>
> <code>
> void main(){}
> static this(){}
> static this(){}
> <\code>
That's because there are two static constructors, which is not legal.
|
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright escribió: > BCS wrote: >> this gives a link error with somthing about duplicate symbols. >> >> <code> >> void main(){} >> static this(){} >> static this(){} >> <\code> > > That's because there are two static constructors, which is not legal. But it could be caught at compile time, instead, giving an appropriate error message. -- Carlos Santander Bernal |
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | Carlos Santander wrote:
> Walter Bright escribió:
>> BCS wrote:
>>> this gives a link error with somthing about duplicate symbols.
>>>
>>> <code>
>>> void main(){}
>>> static this(){}
>>> static this(){}
>>> <\code>
>>
>> That's because there are two static constructors, which is not legal.
>
> But it could be caught at compile time, instead, giving an appropriate error message.
>
quote from the spec
"Order of Static Construction within a Module
Within a module, the static construction occurs in the lexical order in which they appear."
doesn't this imply that multiple static constructors are legal?
|
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | On Wed, 07 Jun 2006 22:34:27 +1000, Johan Granberg <lijat.meREM@OVEgmail.com> wrote: > Carlos Santander wrote: >> Walter Bright escribió: >>> BCS wrote: >>>> this gives a link error with somthing about duplicate symbols. >>>> >>>> <code> >>>> void main(){} >>>> static this(){} >>>> static this(){} >>>> <\code> >>> >>> That's because there are two static constructors, which is not legal. >> But it could be caught at compile time, instead, giving an appropriate error message. >> > > quote from the spec > "Order of Static Construction within a Module > > Within a module, the static construction occurs in the lexical order in which they appear." > > doesn't this imply that multiple static constructors are legal? 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 ... module test; class Foo { static this() { ... } } class Bar { static this() { ... } } static this() { . . .} In this case, Foo's ctor runs first, then Bar's and finally the module's. The spec does not mean that one can have multiple class ctors per class or module ctors per module. -- Derek Parnell Melbourne, Australia |
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | 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
|
June 07, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johan Granberg | 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
|
June 08, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | 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 |
June 08, 2006 Re: link error for 2+ static this() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander | On Wed, 07 Jun 2006 14:36:40 -0500, Carlos Santander wrote: >>> 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 ... I think that's cool! Me too! I have suggested this to Walter some time back, and there is a syntactical precedence with the way that the 'scope' statements work. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 8/06/2006 12:08:23 PM |
Copyright © 1999-2021 by the D Language Foundation