getting to know dmd and druntime

David Nadlinger see at klickverbot.at
Sun Jul 22 06:11:00 PDT 2012


On Sunday, 22 July 2012 at 10:42:58 UTC, Nick Sabalausky wrote:
> Actually, that's just a clever illusion. Your main() method 
> isn't
> really the first thing called, the first thing called is a 
> function in
> druntime called dmain (or Dmain or _dmain or something like 
> that, I
> forget offhand). This function does all the initial stuff like 
> calling
> all the static/module constructors, initializing druntime 
> including the
> GC, some other stuff, and then actually calling *your* main().

It's the other way round. Your main() function gets mangled as 
_Dmain by the compiler, and druntime has the real (C) main(). On 
linking, the undefined reference to _Dmain in druntime is 
resolved to the user-supplied D function.

The D main() is also special in that the compiler transparently 
rewrites all the »reduced« signatures (without return value and 
param array) to the full one.

David


More information about the Digitalmars-d-learn mailing list