getting to know dmd and druntime

maarten van damme maartenvd1994 at gmail.com
Sun Jul 22 04:52:56 PDT 2012


2012/7/22 Nick Sabalausky <SeeWebsiteToContactMe at semitwist.com>:
> 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().
>
> IIRC, this dmain function is in object.d.
>

I've looked and it appears to be in rt/dmain2.d .
Great to know that my main() function isn't the first function called,
this explains a lot for me.

It looks like what I need is a function with the signature
extern (C) int main(int argc, char** argv)
which initializes the garbage collector etc.

To compile it I would need a function with signature
"_Dmodule_ref"
What is this and where does it come from?
(Got this information from
http://www.mail-archive.com/digitalmars-d@puremagic.com/msg89241.html)

I'm trying to compile my file with only extern (C) int main with
-defaultlib=none and -debuglib=none but the resulting executable is 31
kb so I'm pretty sure druntime is still beeing mixed in.


More information about the Digitalmars-d-learn mailing list