Functions that don't return
KW Heuer
kwh at bentley.UUCP
Thu Mar 27 04:26:17 AEST 1986
The datatype "void" was introduced to distinguish functions which return
an int from those which return no useful value but were commonly declared
int by default. ("extern f();" still means "extern int f();".)
There are a few functions which don't return to the caller at all:
exit(), _exit(), and longjmp() come to mind. Many users write their
own (usage(), error()). These are normally declared void, which is
better than int but still not technically correct.
"void" should mean that the function returns, but has no useful value.
There should be a new keyword, e.g. "flowsink", to describe a function
that never returns at all.
I can see three advantages in this scheme. The user is saying what he
means, making the code clearer at minimal cost; the compiler would be
able to produce slightly more efficient code ("else" following "exit()"
could be ignored, like "else" following "goto" or "break"); and lint
could dispense with the /* NOTREACHED */ kludge.
Comments?
Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
More information about the Comp.lang.c
mailing list