main return value

cschmidt at lynx.northeastern.edu cschmidt at lynx.northeastern.edu
Mon May 13 08:33:52 AEST 1991


Forgive me if you have seen this message already.  I first posted this
12 days ago and have not seen it yet on our copy of the comp.lang.c
newsgroup; nor have I seen or received any responses.

What value should the standard function MAIN return?  I ran into this
question when porting some programs from DOS to VMS.  Alternatives:

1.  Declare the MAIN return type as VOID and do not return any value
    to the compiler's exit routines.  The problem with this is that
    when the program actually terminates, it will return a non-zero
    value to DOS as the "exit code".

2.  Declare the MAIN return type as VOID and terminate the function
    with the line "exit (EXIT_SUCCESS)".  The problem with this is
    that the VAX C compiler displays an error message (warning level)
    when the return type of the function MAIN is VOID.

3.  Declare the MAIN return type as INT and terminate the function
    with the line "return EXIT_SUCCESS".  The problem with this is
    that EXIT_SUCCESS is zero, even in the VAX version, and when a VMS
    program terminates and returns zero to VMS, VMS displays the
    system message for status code zero.  (The universal status code
    for success in VMS is one, not zero.)

4.  Declare the MAIN return type as INT and terminate the function
    with the line "return MAIN_SUCCESS", where MAIN_SUCCESS is an
    application-defined OS-dependent macro (which would be zero for
    DOS, one for VMS).  This is the only solution I can think of right
    now that would be lint-free and that would not cause the program
    to return a non-success error status code to the OS.

I expect many experienced C programmers will be surprised to learn
that it is impossible to write a portable, lint-free "hello world"
program in C that compiles and links without errors.

Christopher Schmidt
cschmidt at lynx.northeastern.edu



More information about the Comp.lang.c mailing list