Functions that never return

Ray Butterworth rbutterworth at watmath.UUCP
Thu Sep 25 00:55:45 AEST 1986

> >5) On a similar note it gets rid of the damned /*NOTREACHED*/
> As I pointed out before, this can be handled by making lint smarter:
> "void exit(int) { for (;;); }" should suffice, and doesn't even require a
> new lint-comment.

Exactly where would you put this "void exit(int) {for (;;);}" ?
I imagine you mean putting it in the lint library, but if that is
the case, lint won't see it until the second pass.  It is the first
pass that needs to know that exit() doesn't return, just as it is
there that it needs to know what type it returns, and so this
information must be provided in the header file (or wherever) that
declares exit() as being of type (void).

At the moment, the header file contains at most "extern void exit(int);",
and there is nothing in that statement that indicates that the function
does not return.  To convey this information you must change the language
in some way, either by creating a new type (e.g. (goto)) or by creating
a new lint directive (e.g. /*GOTO*/).  Adding the lint directive is
easier to do; while adding the new type enables the compiler to generate
more efficient code.  The two different compilers we use here use those
two different approaches, and they are very useful for finding sections
of code that are never reached.

More information about the Comp.lang.c mailing list