www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Importing but not linking doesn't create module constructors

reply Brad Beveridge <brad.beveridge somewhere.com> writes:
There is a thread in the main newsgroup with this title that may have more
detail.
Consider this module that wraps a c function
-- wrap.d --
extern (C) { void some_c_func(); };
static this(){
  printf("Will I get printed?\n");
}

In another file, the wrap.d file is imported and you call some_c_func().
Assume that you do link the c object file so that some_c_func() is resolved,
but you DO NOT link the wrap object file.
There are two things that can happen
1) One of your modules has a "static this()" constructor
  - The linker will complain that there is an unresolved symbol, ie the
wrap.d "static this()" constructor is not resolved because it is not
linked.  I think this is correct.

2) None of your modules has a static constructor
 - The linker will link fine, and some_c_func will be resolved & you can
call it.
I think that 2. is a bug, the wrap.d module constructor should still need to
be resolved.

Is this a bug?

Cheers
Brad
Aug 24 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"Brad Beveridge" <brad.beveridge somewhere.com> wrote in message
news:cghcpj$1pj7$1 digitaldaemon.com...
 There is a thread in the main newsgroup with this title that may have more
 detail.
 Consider this module that wraps a c function
 -- wrap.d --
 extern (C) { void some_c_func(); };
 static this(){
   printf("Will I get printed?\n");
 }

 In another file, the wrap.d file is imported and you call some_c_func().
 Assume that you do link the c object file so that some_c_func() is

 but you DO NOT link the wrap object file.
 There are two things that can happen
 1) One of your modules has a "static this()" constructor
   - The linker will complain that there is an unresolved symbol, ie the
 wrap.d "static this()" constructor is not resolved because it is not
 linked.  I think this is correct.

 2) None of your modules has a static constructor
  - The linker will link fine, and some_c_func will be resolved & you can
 call it.
 I think that 2. is a bug, the wrap.d module constructor should still need

 be resolved.

 Is this a bug?

I'm not really sure. The reason for (2) is the compiler inserts code to order module constructors such that imports get constructed first. But if the module doesn't have a constructor, it doesn't need to order them.
Aug 25 2004
parent reply Brad Beveridge <brad.beveridge somewhere.com> writes:
Walter wrote:

 
 "Brad Beveridge" <brad.beveridge somewhere.com> wrote in message
 news:cghcpj$1pj7$1 digitaldaemon.com...
 There is a thread in the main newsgroup with this title that may have
 more detail.
 Consider this module that wraps a c function
 -- wrap.d --
 extern (C) { void some_c_func(); };
 static this(){
   printf("Will I get printed?\n");
 }

 In another file, the wrap.d file is imported and you call some_c_func().
 Assume that you do link the c object file so that some_c_func() is

 but you DO NOT link the wrap object file.
 There are two things that can happen
 1) One of your modules has a "static this()" constructor
   - The linker will complain that there is an unresolved symbol, ie the
 wrap.d "static this()" constructor is not resolved because it is not
 linked.  I think this is correct.

 2) None of your modules has a static constructor
  - The linker will link fine, and some_c_func will be resolved & you can
 call it.
 I think that 2. is a bug, the wrap.d module constructor should still need

 be resolved.

 Is this a bug?

I'm not really sure. The reason for (2) is the compiler inserts code to order module constructors such that imports get constructed first. But if the module doesn't have a constructor, it doesn't need to order them.

require that the constructor for that module be resolved? Brad
Aug 26 2004
parent "Walter" <newshound digitalmars.com> writes:
"Brad Beveridge" <brad.beveridge somewhere.com> wrote in message
news:cgk8f2$3j8$1 digitaldaemon.com...
 Walter wrote:

 "Brad Beveridge" <brad.beveridge somewhere.com> wrote in message
 news:cghcpj$1pj7$1 digitaldaemon.com...
 There is a thread in the main newsgroup with this title that may have
 more detail.
 Consider this module that wraps a c function
 -- wrap.d --
 extern (C) { void some_c_func(); };
 static this(){
   printf("Will I get printed?\n");
 }

 In another file, the wrap.d file is imported and you call



 Assume that you do link the c object file so that some_c_func() is

 but you DO NOT link the wrap object file.
 There are two things that can happen
 1) One of your modules has a "static this()" constructor
   - The linker will complain that there is an unresolved symbol, ie the
 wrap.d "static this()" constructor is not resolved because it is not
 linked.  I think this is correct.

 2) None of your modules has a static constructor
  - The linker will link fine, and some_c_func will be resolved & you



 call it.
 I think that 2. is a bug, the wrap.d module constructor should still



 to
 be resolved.

 Is this a bug?

I'm not really sure. The reason for (2) is the compiler inserts code to order module constructors such that imports get constructed first. But


 the module doesn't have a constructor, it doesn't need to order them.


 require that the constructor for that module be resolved?

I am not sure what the right answer is here.
Aug 26 2004