int main() versus short main()?

In many books/tutorials I find that int main() is always used instead of short main().

Is it even possible to use short instead of int for your main() function?
If so, why not use short if you know that the main() function only returns -1 or 0?
Last edited on
Because the C++ specification states that main shall return an int.
Returning anything else is not compliant with the specification.
Another reason is that int -1 and short -1 look different in binary.
A fun link I like to dig up every now and then:
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/legality-of-void-main.html

Enjoy! :o>
I see, thank you all :).
Out if interest, where did you pick up the value of -1 ??

POSIX and Windows both provide the following defines (in stdlib.h/cstdlib)

1
2
#define EXIT_SUCCESS    0
#define EXIT_FAILURE    1 


So in these case, main should preferably stick to returning 1 or 0, not -1 or 0

But implementations of C and C++ are free to define EXIT_SUCCESS and EXIT_FAILURE as other values. But 0 always means success.

Andy
Last edited on
BTW, don't return negative numbers from main(). It attracts bad karma.
Topic archived. No new replies allowed.