digitalmars.D.bugs - return type of main (should be int or void)
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (28/57) Jan 12 2005 $ dmd main2.d
Some test programs (one-liners):void main() {}$ dmd main1.dvoid main(char[][] args) {}$ dmd main2.dvoid main(char[] string) {}$ dmd main3.d main3.d:1: function main3.main parameters must be main() or main(char[][] args) So far, so good. But then comes:int main() { return 0; }$ dmd main4.dint main(char[][] args) { return 0; }$ dmd main5.dchar[] main() { return "EXIT_SUCCESS"; }$ dmd main6.d i.e. No errors (on Mac OS X), until you run it:$ ./main6; echo $? Bus errorsimilar on Linux, when using the GDC compiler:$ ./main6; echo $? Segmentation faultbut, if you compile it on Linux X86: (with DMD)$ ./main6; echo $? 12I think that main should be *forced* to return int or void, where "void" would mean that the program would return a 0... This would shorten small programs, from:int main() { printf("Hello, World!\n"); return 0; }to:import std.stdio; void main() { writefln("Hello, World!"); }At least some constants from C's /usr/include/stdlib.h could be used, to make D programs more self-documenting:import std.stdio; import std.c.stdlib; int main() { writefln("Hello, World!"); return EXIT_SUCCESS; }In summary, "void main()" should be either defined or invalid - to avoid this: http://users.aber.ac.uk/auj/voidmain.shtml ? Currently it has different results for DMD and GDC compilers.... --anders PS. "12" was of course (?) the length of the string "EXIT_SUCCESS" See my previous post, currently DMD returns register EAX (!): http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/13127
Jan 12 2005