prolog and epilog code
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 2 10:25:21 PDT 2016
On 8/2/16 1:04 PM, Rufus Smith wrote:
> On Tuesday, 2 August 2016 at 16:30:08 UTC, Adam D. Ruppe wrote:
>> On Tuesday, 2 August 2016 at 16:21:07 UTC, Rufus Smith wrote:
>>> How does one use C main? extern C?
>>
>> extern(C) int main()
>>
>> should do it
>
> It doesn't seem to be that easy!
>
> https://wiki.dlang.org/Runtime_internals
This is just explaining how the runtime currently works, not how you
should override it.
It's really easy actually. Example:
$ cat main.c
#include <stdio.h>
extern int rt_init();
extern void d_func();
int main(int argc, char *argv[])
{
printf("hello from C!\n");
rt_init();
printf("done initializing runtime\n");
d_func();
}
$ cat dmain.d
extern(C) void d_func()
{
import std.stdio;
writeln("hello from D!");
}
shared static this()
{
import std.stdio;
writeln("doing some pre-run init!");
}
$ gcc -c main.c
$ dmd dmain.d main.o
$ ./dmain
hello from C!
doing some pre-run init!
done initializing runtime
hello from D!
-Steve
More information about the Digitalmars-d-learn
mailing list