Mail Archives: djgpp/1997/03/14/10:17:25
As an example of the pitfalls of not returning an explicit value from
main: this program
// mainrett.c
int main (int argc, char *argv[]) {
// do nothing and see what gets returned.
}
compiles (but has a warning, no return from function not returning void).
If I run redir -x mainrett, I get this:
Exit code: 2
GCC, for whatever reason, defines the implicit return value as 2. If
people expect 0, a program that lets gcc choose the return value of
main could break some batch files.
(Don't forget what the int is *for*. It's the errorlevel. All my programs
return 0 on normal exit, 1 on error like malloc failure or file not found
or argument syntax error, or if arguments were expected, display a usage
note and return 1, and return 255 on any protection faults, this last
being dictated by CWSDPMI and not my code.)
--
.*. Where feelings are concerned, answers are rarely simple [GeneDeWeese]
-() < When I go to the theater, I always go straight to the "bag and mix"
`*' bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh
- Raw text -