Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!sdd.hp.com!mips!spool.mu.edu!agate!ucbvax!lynx.northeastern.edu!cschmidt From: cschmidt@lynx.northeastern.edu Newsgroups: comp.lang.c Subject: re: main return value Message-ID: Date: 6 Jun 91 17:05:57 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 30 Thanks to all who posted or mailed replies to my question about the "main" function. Sorry for being so tardy in posting this summary. The question was, what normal (ie non-error) value should main return in an ANSI C program? The answer is implied by the following two rules about ANSI C. I am grateful to those who pointed out these rules. Eventually, I found these rules on page 106 in the book "Standard C" by Plauger and Brodie. (1) The main function should be declared as returning int. (2) The statement "return x;" in the body of main is equivalent to "exit (x);". This then is the correct form: #include /* defines EXIT_SUCCESS */ int main (...) { ... return EXIT_SUCCESS; } This issue arose when I was porting some programs to VAX C, which it turns out is not ANSI. VAX C violates rule (2) above. Thanks to those of you who suggested workarounds. It is almost always a programming error when a function declared as returning a value has no "return" statement. Such a function is not what I would call lint-free. Christopher Schmidt cschmidt@lynx.northeastern.edu