Checking Exit Codes

Jim Balter jim at segue.segue.com
Mon Nov 5 07:17:46 AEST 1990


In article <18689 at rpp386.cactus.org> jfh at rpp386.cactus.org (John F. Haugh II) writes:
>as i said, it was a fake example.  you pay your money, you take your chances.

I hope no one is paying you money for your advice.

>i typically don't use assert, for exactly the reasons i've mentioned.  if i
>want a core dump, i write "abort()".  if i want an error message, i use
>perror or fprintf.

And if you want to make an assertion about a logical state, you ...
oh, a new concept for you, eh?

>but i have found assert to vary from machine to machine
>enough to be useless.

In other words, all your talk about how to use assert portably is hot air.
Why did you bother?

The fact of the matter is that there is plenty of portable code that uses
assert, without an explicit call to exit.  What assert does after it prints a
message is irrelevant to portability because proper usage of assert (as opposed
to your examples) in working code never prints a message.  An assertion failure
should only occur during debugging, and indicates a logic error in the program.
The fact that some implementations may return from assert if SIGABORT is
ignored is irrelevant because (a) no real program ignores SIGABORT (b) the
printing of an assert message is an indication that the program has
malfunctioned and needs debugging, and the behavior of the program *after* the
assert message is printed is of little concern.  And whether abort dumps core
or not is an issue outside the ANSI C standard and is hardly a portability
issue.  Once you get an assert failure; it is time to debug; you can force all
the core dumps you want.



More information about the Comp.unix.internals mailing list