Question regarding D v.0110

Steven Schveighoffer schveiguy at gmail.com
Mon Jul 13 16:35:26 UTC 2020


On 7/13/20 9:33 AM, Remi wrote:
> On Monday, 13 July 2020 at 12:25:33 UTC, Steven Schveighoffer wrote:
>>
>> Though it depends on usage -- perhaps a Rand is useless without a seed 
>> set?
>>
>> As I suspected, the static ctor could easily be marked standalone (as 
>> in, it can't be part of a cycle, because it doesn't depend on any 
>> other module to run). This is quite frequently one of the biggest 
>> problems with D's static ctors.
>>
> 
> Interesting, is that a language feature? I found the "shared static 
> constructors" in the documentation which I think could be used here and 
> would achieve the same thing but might also be covered by cyclicity 
> checks, do you know?

The difference between shared and not-shared is that shared constructors 
run once per program, whereas non-shared constructors run once per thread.

This is D1, so likely it's equivalent to running shared constructors. 
But it depends on whether there are multiple threads.

There is no feature right now that allows you to mark a ctor as 
standalone. But the compiler will mark some of them as standalone if it 
can determine that it's that way.

-Steve


More information about the Digitalmars-d mailing list