[comp.sys.amiga.tech] main and ANSI C

GIGUERE@WATCSG.BITNET (Eric Giguere) (02/25/89)

Jim Crotinger (crotinger%mit.mfenet@nmfecc.arpa) writes:

>  A couple of the books I have, one on ANSI C, state that returning a value
>from main should be identical to calling exit(). In fact, they say it is
>perfectly allowable for the startup code to execute main() with the following
>call:
>
>  exit(main(argc,argv));

This is correct -- section 2.1.2.2 of the ANSI Standard states:

  "A return from the initial call to the main function is equivalent
   to calling the exit funciton with the value returned by the main
   function as its argument.  If the main function executes a return
   that specifies no value, the termination status returned to the
   host environment is undefined."

>  In this respect, Lattice is in error since it prototypes main as being
>type void, where all the books I've seen (ANSI books) say main should have
>type int.


Yes, this is true, but if the return value is ignored the point is
moot.  Personally I prefer to declare main like this:

    main( int argc, char **argv )
      {
       ...
      }

without any type specification.  Thus it defaults to int but if
you don't care about the return value you use 'return;' or just
fall out of the function.


Eric Giguere
Computer Systems Group, University of Waterloo

BITNET: GIGUERE@WATCSG         Other: giguere@watcsg.UWaterloo.CA