main return value

Roy Johnson rjohnson at shell.com
Wed May 22 02:31:02 AEST 1991


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.  [...]
   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.

How about declaring MAIN to return type INT, and terminate the function
with
  exit(EXIT_SUCCESS);
  return 0;

The return value of 0 will never be reached, but the compiler will
not complain, and you'll always get success.

   [3.  ... 4. ...]

   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.

Actually, it is possible; it's just that the interpretation of the
return value is up to the platform.
--
=============== !You!can't!get!here!from!there!rjohnson ===============
Feel free to correct me, but don't preface your correction with "BZZT!"
Roy Johnson, Shell Development Company



More information about the Comp.lang.c mailing list