Subhuman
asked on
int main() returns?
Looking through the documentation for my compiler, it says that there are special meanings (in DOS) for values returned by main(), but it doesn't actually specify what means what.
What are these return values that DOS recognises, and what do they mean?
What are these return values that DOS recognises, and what do they mean?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> erroneous warning
Indeed, main /must/ return an integer so it should be an error message :)
3.6.1:
2 An implementation shall not predefine the main function. This func-
tion shall not be overloaded. It shall have a return type of type
int, but otherwise its type is implementation-defined.
...
>> special meanings (in DOS) for values returned by main(), but it
>> doesn't actually specify what means what
There are no standardized meanings, though errorlevel 0 is indeed often used as 'no-error-occured'
Indeed, main /must/ return an integer so it should be an error message :)
3.6.1:
2 An implementation shall not predefine the main function. This func-
tion shall not be overloaded. It shall have a return type of type
int, but otherwise its type is implementation-defined.
...
>> special meanings (in DOS) for values returned by main(), but it
>> doesn't actually specify what means what
There are no standardized meanings, though errorlevel 0 is indeed often used as 'no-error-occured'
KangaRoo:
3.6.1.
-5-
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing
return 0;
-----------------------
Sometimes it is useful to read till the end ;-))
3.6.1.
-5-
A return statement in main has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing
return 0;
-----------------------
Sometimes it is useful to read till the end ;-))
:-\
ASKER
Borland compilers allow you to compile the main method with a return type of void, as well, although I tend to avoid this now.
Thanks for the feedback folks, I'll grade this at home later.
Thanks for the feedback folks, I'll grade this at home later.
EXIT STATUS
The following exit values are returned:
0 One or more matches were found.
1 No matches were found.
2 Syntax errors or inaccessible files (even if
matches were found).
So if you really need to differentiate between error codes, you can try to find out similar commands/programs and check what do they return.
Now, second part (and it would be good, if it is enough for you) is C++-laguage specific.
The standard requires cstdlib header files to contain two macros EXIT_SUCCESS and EXIT_FAILURE. So, maybe the easiest way for you is to return EXIT_FAILURE in case of any error, note also if your program does not return anything, it is equivalent to
return 0; // EXIT_SUCCESS
MSVC produces erroneous warning in this case.
Hope it helps