Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rice!rice!sun-spots-request From: richard@unipalm.co.uk Newsgroups: comp.sys.sun Subject: exit() and return() in a C program Keywords: Miscellaneous Message-ID: <1990Aug14.232717.16846@rice.edu> Date: 13 Aug 90 10:16:51 GMT Sender: sun-spots-request@rice.edu Organization: Sun-Spots Lines: 48 Approved: Sun-Spots@rice.edu Originator: spots@titan.rice.edu X-Sun-Spots-Digest: Volume 9, Issue 304, message 8 X-Refs: Original: v9n298 > 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@xtech.uucp XTech, Cambridge, England ukc!acorn!unipalm!xtech!richard Tel: +44 954 211862 richard@unipalm.uucp