main return value, struct padding
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jan 20 09:21:36 PST 2009
"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:
[steves at localhost testing]$ cat testmainreturn.d
void main()
{
return 1;
}
[steves at localhost testing]$ cat testmainreturn2.d
void main()
{
}
[steves at localhost testing]$ dmd testmainreturn.d
[steves at localhost testing]$ dmd testmainreturn2.d
[steves at localhost testing]$ ./testmainreturn
[steves at localhost testing]$ echo $?
1
[steves at localhost testing]$ ./testmainreturn2
[steves at localhost testing]$ echo $?
0
[steves at localhost testing]$ dmd | grep "Digital Mars D"
Digital Mars D Compiler v1.038
[steves at localhost testing]$
disassembly:
[steves at localhost testing]$ obj2asm testmainreturn.o
...
_Dmain:
push EBP
mov EBP,ESP
mov EAX,1
pop EBP
ret
.text._Dmain ends
...
[steves at 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
More information about the Digitalmars-d-learn
mailing list