'exit(1);' considered useless (slight flame)
Gordon Moffett
gam at proper.UUCP
Tue Feb 7 16:01:16 AEST 1984
As a maintainer and supporter of existing software, I am getting
tired of programs whose terminating action is:
exit(1);
A typical application is:
p = malloc(n);
if (p == NULL) {
exit(1);
}
Bad enough that the original programmer didn't code for an error message,
but furthermore was content to just provide a `non-zero' error code.
In intro(2) of volume 1 of the Unix manual set are described the various
error codes returned by system calls and subroutines. There is an
external variable (int) called `errno' where these error codes are
stored when applicable. So, programmers, please use:
exit(errno);
... whenever possible, so I don't have to recode it for you.
It is useful to reference the exit status of a command and have it
provide more meaningful information that just a non-zero value.
Thank you.
SEE ALSO
perror(3)
"lint vs. strong typing - programmers' responsibitly", Usenet:
net.lang
--
Gordon A. Moffett
{ allegra, decvax!decwrl } !amd70!proper
hplabs!intelca!proper!gam
More information about the Comp.lang.c
mailing list