digitalmars.D - return code of main
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (18/18) Nov 29 2004 Would it be possible to change the D declaration
- Thomas (5/23) Nov 29 2004 If you play a little around, you'll notice that the "return" value is ps...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/15) Nov 29 2004 returns
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'"
Nov 29 2004
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
Nov 29 2004
Thomas wrote:You are correct. (with DMD compiler)* 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.$ cat returncode.d void main() { asm { mov EAX, 42; } }returns$ ./returncode; echo $? 42Still returns 1 with gdc, though... I think it should either be an error, or return 0 always ? --anders
Nov 29 2004