digitalmars.D.bugs - Importing but not linking doesn't create module constructors
- Brad Beveridge (24/24) Aug 24 2004 There is a thread in the main newsgroup with this title that may have mo...
- Walter (7/29) Aug 25 2004 resolved,
- Brad Beveridge (4/38) Aug 26 2004 But wrap.d does have a constructor. Shouldn't the act of importing a mo...
- Walter (8/45) Aug 26 2004 some_c_func().
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
"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() isresolved,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 needtobe 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
Walter wrote:"Brad Beveridge" <brad.beveridge somewhere.com> wrote in message news:cghcpj$1pj7$1 digitaldaemon.com...But wrap.d does have a constructor. Shouldn't the act of importing a module require that the constructor for that module be resolved? BradThere 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() isresolved,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 needtobe 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 26 2004
"Brad Beveridge" <brad.beveridge somewhere.com> wrote in message news:cgk8f2$3j8$1 digitaldaemon.com...Walter wrote:some_c_func()."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 callcanAssume that you do link the c object file so that some_c_func() isresolved,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 & youneedcall it. I think that 2. is a bug, the wrap.d module constructor should stilliftobe 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. Butmodulethe module doesn't have a constructor, it doesn't need to order them.But wrap.d does have a constructor. Shouldn't the act of importing arequire that the constructor for that module be resolved?I am not sure what the right answer is here.
Aug 26 2004