exit() and return() in a C program
richard at unipalm.co.uk
richard at unipalm.co.uk
Mon Aug 13 20:16:51 AEST 1990
> titan% cat test.c
> main()
> {
> }
> titan% lint test.c
> test.c(3): warning: main() returns random value to invocation
> environment
Your declaration of main is taken by the compiler to mean that it returns
the default type (int). Therefore no return statement is not allowed, and
will indeed return a random value to the calling environment.
Adding an exit line does not help lint, it has no way of knowing that the
exit function actually exits. Lint has various mechanisms to allow the
programmer to tell lint information about the program. A case of RTFM
mainly.
In this particular case, if your main function ever returns, you should
have a return statement, if it always exits, you should tell lint that it
will never get to the end of the routine.
e.g.
/*ARGSUSED*/
int main(argc, argv)
int argc;
char **argv;
{
...
return(some_value);
}
or
/*ARGSUSED*/
int main(argc, argv)
int argc;
char **argv;
{
...
exit(0);
/*NOTREACHED*/ /* tells lint that this line is never reached */
}
Richard Nuttall richard at xtech.uucp
XTech, Cambridge, England ukc!acorn!unipalm!xtech!richard
Tel: +44 954 211862 richard at unipalm.uucp
More information about the Comp.sys.sun
mailing list