On Monday, 8 April 2013 at 11:21:07 UTC, Jacob Carlborg wrote:
On 2013-04-08 11:51, Maxim Fomin wrote:
C main function need to be renamed or D main function should
be supplied
(then a program would start from C code, not D, but this is
not a problem)
By the way, druntime links to _Dmain, but does not necessarily
forwards
to it.
The C main function defined in druntime forward to the D main
function. The C main function calls "_d_run_main" and passes in
a pointer to the D main function. "_d_run_main" then calls the
d main function. Indirectly the C main forwards to D main.
This is exactly why main() does not necessarily forwards to
_Dmain().
import std.stdio;
alias extern(C) int function(char[][] args) MainFunc;
extern (C) int _d_run_main(int argc, char **argv, MainFunc
mainFunc);
extern(C) int main(int argc, char** argv)
{
return _d_run_main(argc, argv, &bar);
}
void main()
{
writeln("D main");
}
extern(C) int bar(char[][] args)
{
writeln("bar");
return 0;
}
Guess what would happen.