Strange lint mumblings

Ray Butterworth rbutterworth at watmath.waterloo.edu
Fri Dec 16 09:27:00 AEST 1988


In article <416 at marob.MASA.COM>, daveh at marob.MASA.COM (Dave Hammond) writes:
> Can anyone explain why the statement:
>     exit(0);    /* followed immediately by main's closing brace */
> causes lint to complain:
> (137)  warning: main() returns random value to invocation environment

If your <stdlib.h> doesn't have something like "extern void /*GOTO*/ exit();"
in it (not many do), then your lint doesn't know that exit() never returns.

In that case, you have to code your example as:
        ...
        exit(0);
        /*NOTREACHED*/
    }

Most versions of lint take this comment to mean that it should pretend
that it had just processed an unconditional goto.

The big disadvantage of NOTREACHED is that lint will only tell you
something useful if you use it correctly, rather than if you forget
to use it (e.g. exit(0); x=5; return x;).

The disadvantage of NOTREACHED and GOTO is that the compiler can't
recognize them and use the knowledge to optimize the code.
Overloading a keyword, as in "extern goto exit();" in a header file
would be an ideal solution, but as you can probably guess:  that's not C.




More information about the Comp.lang.c mailing list