any tool to at least partially convert C++ to D (htod for source

Michel Fortin michel.fortin at michelf.com
Thu Mar 11 18:16:48 PST 2010


On 2010-03-11 13:26:17 -0500, Walter Bright <newshound1 at digitalmars.com> said:

> Max Samukha wrote:
>> Michel Fortin wrote:
>> 
>>> 
>>> I'd like to point out that the trick of creating a separate module to 
>>> initialize another one is not much safer than C++ static initialization.
>>> 
>>> Take for instance std.stdio which it is initialized by std.stdiobase's 
>>> static constructor. If your module import std.stdio and attempt to use 
>>> the standard input/output/error streams in a static constructor, there 
>>> is no guaranty that std.stdiobase static constructor will have been 
>>> called before yours (unless you also import std.stdiobase). It might 
>>> end up crashing depending on link order.
>> 
>> If your module imports std.stdio, std.stdiobase's static constructor is 
>> guaranteed to run before your module's static constructors because your 
>> module depends on std.stdiobase indirectly via std.studio.
> 
> Max is correct. This is not a problem, because the dependency checking 
> is transitive.

Ah, you're right indeed. I thought it was std.stdiobase that imported 
std.stdio, but its the reverse so it's a little better.

Still, std.stdiobase uses this clever external definition to avoid a 
circular import:

	extern(C) void std_stdio_static_this();

This hack is basically just a bypass of the circular dependency check 
for one module. If more than one module use it, you're at risk of 
having the behaviour dependent on the link order.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list