What happens when you launch a D application ?
John Colvin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 22 03:19:40 PDT 2015
On Friday, 22 May 2015 at 06:36:27 UTC, Suliman wrote:
> On SO[1] I got next answer:
>
> "What happens when you launch a D application ? The entry point
> is a C main inside the runtime, which initialize it (the
> runtime), including module constructor, run the unittest (if
> you've compiled with -unittest), then call your main (which
> name is "_Dmain" - useful to know if you want to set a
> breakpoint with GDB). When Vibe.d's main is called, it parses
> command line argument, an optional config file, and finally,
> starts the event loop. Any code that wish to run once the event
> loop has started should use runTask and similar, or
> createTimer. They should not call the code directly from the
> static constructor (it's actually one of the most common
> mistake when starting with Vibe.d)."
>
> Could you explain what mean "C main inside the runtime". I
> thought that is only one main is possible. And why it's named
> "*ะก* main" D is not C-translated language.
>
> Same question is about _Dmain -- what is it?
>
> If I will call this() before main? What it will be? Will it run
> before main?
>
> [1]
> http://stackoverflow.com/questions/30302161/cant-connect-to-mysql-mariadb-database-from-vibed-app
Glossing over a lot of the detail:
"_Dmain" is the symbol that is generated in the object file for
the function called "main" in your source code. A symbol "main"
is also generated, which is where the OS starts the whole
program*. It sets up the runtime and module constructors etc. and
then calls _Dmain.
*It's sometimes called the "C main" because it's equivalent to
"main" in C.
More information about the Digitalmars-d-learn
mailing list