"bearophile" wrote
>I post this here, but if later I see it fit I may post something in the
>main D group too.
>
> D allows to have the main() function of type void too. In such case I'd
> like the program return 0 by default. If people agrees, this can become a
> feature request.
A test:
[ste...@localhost testing]$ cat testmainreturn.d
void main()
{
return 1;
}
[ste...@localhost testing]$ cat testmainreturn2.d
void main()
{
}
[ste...@localhost testing]$ dmd testmainreturn.d
[ste...@localhost testing]$ dmd testmainreturn2.d
[ste...@localhost testing]$ ./testmainreturn
[ste...@localhost testing]$ echo $?
1
[ste...@localhost testing]$ ./testmainreturn2
[ste...@localhost testing]$ echo $?
0
[ste...@localhost testing]$ dmd | grep "Digital Mars D"
Digital Mars D Compiler v1.038
[ste...@localhost testing]$
disassembly:
[ste...@localhost testing]$ obj2asm testmainreturn.o
...
_Dmain:
push EBP
mov EBP,ESP
mov EAX,1
pop EBP
ret
.text._Dmain ends
...
[ste...@localhost testing]$ obj2asm testmainreturn2.o
...
_Dmain:
push EBP
mov EBP,ESP
xor EAX,EAX
pop EBP
ret
.text._Dmain ends
...
So it appears it returns 0 unless you return something else (!)
-Steve