Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 25, 2004 Importing but not linking doesn't create module constructors | ||||
---|---|---|---|---|
| ||||
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 |
August 25, 2004 Re: Importing but not linking doesn't create module constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Beveridge | "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 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? 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. |
August 26, 2004 Re: Importing but not linking doesn't create module constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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
> 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?
>
> 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.
But wrap.d does have a constructor. Shouldn't the act of importing a module require that the constructor for that module be resolved?
Brad
|
August 26, 2004 Re: Importing but not linking doesn't create module constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Beveridge | "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 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? > > > > 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. > But wrap.d does have a constructor. Shouldn't the act of importing a module > require that the constructor for that module be resolved? I am not sure what the right answer is here. |
Copyright © 1999-2021 by the D Language Foundation