main return value
Adrian McCarthy
adrian at mti.mti.com
Wed May 15 01:54:50 AEST 1991
In article <1991May13.091939.9042 at klaava.Helsinki.FI> wirzeniu at kruuna.Helsinki.FI (Lars Wirzenius) writes:
>In article <memo.1010816 at lynx.northeastern.edu> cschmidt at 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.
More information about the Comp.lang.c
mailing list