Subject: Re: main return...
To: Waldi Ravens <waldi@moacs.indiv.nl.net>
From: Erik Bertelsen <erik@sockdev.uni-c.dk>
List: current-users
Date: 03/26/1996 10:14:43
On Mon, 25 Mar 1996, Waldi Ravens wrote:

.. der Mouse wrote:
..
.. > After all, until this discussion came up, I thought "void main(void);"
.. > was one of the allowed declarations for main, and quite a lot of my
.. > code is written that way.
..
.. There are lots of cases where "void main(void);" is allright. For
.. example when the program never exits in a normal fashion, or if
.. the program only exits via a direct or indirect _exit() call.
..
Just to clarify. The following is a citation from ISO/IEC 9899, the
International Standard for C:

::::::::::::::::::::::::
5.1.2.2.1 Program startup
 The function called at program startup is named main. The implementation
delcares no prototype for this function. It can be defined with no
parameters:

  int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any
names may be used, as they are local to the function in which they are
declared):

  int main(int argc, chyar *argv[]) { /* ... */ }
:::::::::::::::::::::::::

and
:::::::::::::::::::::::::::.
5.1.2.2.3 Program Termination
 A return from the initial call to the main function is equivalent to
calling the exit function 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 to the host environement is undefined
::::::::::::::::::::::::::

My conclusion: A C program with a main() whose return type is void
is a non-conforming, i.e. an incorrect C program according to the
standard.

The compiler is allowed to do almost anything if main returns with no
value, incl. producing a diagnostic or just ignoring the case. I'm not
sure whether or not this also covers the case of a main with no return or
exit calls, but I tend to think so.

regards
Erik Bertelsen