order of static constructor execution

Regan Heath regan at netmail.co.nz
Tue Mar 16 03:28:43 PDT 2010


Walter Bright wrote:
> Regan Heath wrote:
>> Walter Bright wrote:
>>> Regan Heath wrote:
>>>> Walter Bright wrote:
>>>>> Regan Heath wrote:
>>>>>> I expect this either isn't possible or falls into the 'possible up 
>>>>>> to a point' category.
>>>>>
>>>>>
>>>>> It's possible up to a point, that point being the parts of the 
>>>>> program the compiler does not see.
>>>>
>>>> So.. isn't that the same point the current import dependency method 
>>>> stops at?
>>>
>>> No, because that's a runtime check.
>>
>> No, I'm no longer suggesting a runtime solution.
>>
>> How does 'unreachable code' detection in C/C++ compilers work?
> 
> It requires the source code so the compiler can look at it.
> 
>> Can you use something similar to figure out the order module static 
>> data is used?
> 
> Yes, but that fails when the compiler doesn't have the source code to 
> look at.

Ahh.. I was naively assuming you were compiling all the source at the 
same time, but of course that's not necessarily true.

So, this needs to work when compiling modules seperately and then 
linking, likewise libraries, right?  Is that the problem you're 
referring to?

Couldn't you store a list of dependencies in usage order in the output 
of the compile (the .o[bj] file) and use these lists when linking to 
resolve module init order.  You would need to know the 'main' module for 
a starting point, but from there you should be able to create an 
ordering.  You'd probably want to treat a static library as a single 
dependency, likewise C libraries etc.

R



More information about the Digitalmars-d mailing list