Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jarthur!mti!adrian From: adrian@mti.mti.com (Adrian McCarthy) Newsgroups: comp.lang.c Subject: Re: main return value Message-ID: <2824@mti.mti.com> Date: 14 May 91 15:54:50 GMT References: <1991May13.091939.9042@klaava.Helsinki.FI> Reply-To: adrian@cursa.UUCP (Adrian McCarthy) Organization: Micro Technology, Anaheim, CA Lines: 43 In article <1991May13.091939.9042@klaava.Helsinki.FI> wirzeniu@kruuna.Helsinki.FI (Lars Wirzenius) writes: >In article cschmidt@lynx.northeastern.edu writes: >>What value should the standard function MAIN return? I ran into this >>question when porting some programs from DOS to VMS. Alternatives: >> >>1. [void main(), no exit code] >>2. [void main(), exit(EXIT_SUCCESS)] >>3. [int main(), return EXIT_SUCCESS] >>4. [int main(), return MAIN_SUCCESS] >>[EXIT_SUCCESS == 0 causes problems in VMS] > >According to the standard ... First of all, VAX C does not claim to be standard. Fortunately, however, many of its behaviors do conform to the standard. >If it is true that the VMS C compiler defines EXIT_SUCCESS as 0, and the >operating systems interprets that as failure, But EXIT_SUCCESS wasn't defined for use by the environment. It was defined for use with exit(). > then I would think that >the VMS C compiler has a bug (actually, I think that the standard says >that 0 should always indicate success, regardless of environment, I >don't have any reference book handy, however; it would mean that VAX C >should translate exit(0) to 1, and vice versa). VAX C does map exit(0) to SS$_NORMAL (1). But if you look over that list of alternatives, this (working) solution was omitted: 5. [int main(), exit(EXIT_SUCCESS)] This is both portable and ANSI compliant. It is unecessary to redefine EXIT_SUCCESS. EXIT_SUCCESS and EXIT_FAILURE are defined solely for use with the exit() function (that's why these symbols are prefixed with EXIT_). Now K&R 2 does contain the provacative statement: ``Within main, return expr is equivalent to exit(expr).'' [p. 164] So *if* VAX C were compliant, we would expect it to treat the return from main() as a special case, doing all the same mappings. Currently it does not do that. Aid.