Mail Archives: djgpp/2000/08/23/08:30:23
Chris Amos wrote:
> return 0; // Can anyone tell me whats so special about 0? Why 0?
There are three standard return values: 0, EXIT_SUCCESS and
EXIT_FAILURE. (You need to #include <stdlib.h> for the last two.)
0 and EXIT_SUCCESS indicate success, and EXIT_FAILURE indicates
failure of some sort.
> // I mean, whats so special about it? Is is an exit code of
> // some kind? Can i use any number I want or none at all?
You can't return none at all - or at least you're not supposed to.
The return type of main() is int, so you should return an int, or
who knows what will happen? (The new C standard actually allows
you to omit the return from main() altogether, but this just results
in an implicit return 0.)
> // How about return 69; or return; ? Would those work?
You can return other values, but their meaning is system dependent.
In DOS batch files you can test the return value using ERRORLEVEL,
and you can do something similar in Unix shell scripts.
By the way, you probably shouldn't use // comments in C if you
care about portability. The new C standard allows it, but the
old one (which all current compilers follow) doesn't.
S.
- Raw text -