Thread overview | |||||
---|---|---|---|---|---|
|
November 29, 2004 return code of main | ||||
---|---|---|---|---|
| ||||
Would it be possible to change the D declaration "void main() {}" to return 0 back to the shell ? Currently it seems to return "1", or failure*... (as per C macros: EXIT_SUCCESS=0, EXIT_FAILURE=1) Which makes that you must use the somewhat longer "int main() { return 0; }", just to make it happy. (if you actually wanted to read arguments and return a code, you'd probably use: "int main(char[] args)") Allowing "void main()" would be a nice improvement over ANSI C, which has the same main restrictions. That is: if you declare main as void, the compiler should explicitly insert a "return 0;" equivalent. --anders * For some reason, DMD on Linux returns a "12" ??? Seems like all bets are off now, you can even declare stuff like "float main()" (for fuzzy return states?) GCC does at least whine, in the same situation: "warning: return type of `main' is not `int'" |
November 29, 2004 Re: return code of main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | In article <cof1cb$p8$1@digitaldaemon.com>, Anders says; > > >Would it be possible to change the D declaration >"void main() {}" to return 0 back to the shell ? > >Currently it seems to return "1", or failure*... >(as per C macros: EXIT_SUCCESS=0, EXIT_FAILURE=1) > > >Which makes that you must use the somewhat longer >"int main() { return 0; }", just to make it happy. > >(if you actually wanted to read arguments and return >a code, you'd probably use: "int main(char[] args)") > > >Allowing "void main()" would be a nice improvement >over ANSI C, which has the same main restrictions. > >That is: if you declare main as void, the compiler >should explicitly insert a "return 0;" equivalent. > >--anders > >* For some reason, DMD on Linux returns a "12" ??? > > Seems like all bets are off now, you can even declare > stuff like "float main()" (for fuzzy return states?) > > GCC does at least whine, in the same situation: > "warning: return type of `main' is not `int'" If you play a little around, you'll notice that the "return" value is pseudo random. I guess that whatever value is stored in EAX will be "returned" to the shell. Thomas |
November 29, 2004 Re: return code of main | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas | Thomas wrote: >>* For some reason, DMD on Linux returns a "12" ??? > > If you play a little around, you'll notice that the "return" value is pseudo > random. I guess that whatever value is stored in EAX will be "returned" to the > shell. You are correct. (with DMD compiler) > $ cat returncode.d > void main() { asm { mov EAX, 42; } } returns > $ ./returncode; echo $? > 42 Still returns 1 with gdc, though... I think it should either be an error, or return 0 always ? --anders |
Copyright © 1999-2021 by the D Language Foundation