www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - link error for 2+ static this()

reply BCS <BCS_member pathlink.com> writes:
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.
Jun 01 2006
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFEgEz+3w+/yD4P9tIRAs4LAJ9Y0dNAB+IuqXlkKRPzPSWve3we1QCgz9Bb UJfUDGgaFrPBvGgtNtHiXAk= =5Dum -----END PGP SIGNATURE-----
Jun 02 2006
prev sibling parent reply Walter Bright <newshound digitalmars.com> writes:
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.
Jun 07 2006
parent reply Carlos Santander <csantander619 gmail.com> writes:
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
Jun 07 2006
parent reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
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?
Jun 07 2006
parent reply "Derek Parnell" <derek psych.ward> writes:
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
Jun 07 2006
parent reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
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
Jun 07 2006
parent reply BCS <BCS pathlink.com> writes:
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
Jun 07 2006
parent reply Carlos Santander <csantander619 gmail.com> writes:
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
Jun 07 2006
parent Derek Parnell <derek psych.ward> writes:
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
Jun 07 2006