[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: can main() return other than int/void ?



archan forced the electrons to say:
> ANSII std is only int and void

Maybe it is - but the official ANSI standard is only int.

Here is the relevant section from the standard:

       5.1.2.2.1  Program startup

       [#1]  The  function called at program startup is named main.
       The implementation declares no prototype for this  function.
       It  shall  be  defined with a return type of int and 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, char *argv[]) { /* ... */ }

       or equivalent(8)  or in  some  other  implementation-defined
       manner.

With footnote (8) being:

       8) Thus, int can be replaced by a typedef  name  defined  as
          int,  or the type of argv can be written as char ** argv,
          and so on.

The words 'implementation-defined manner' allows for main as:

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

or some such non-portable silliness. But ANSI is explicit about the
'main returns an int' part.

Binand

PS: Now someone please post the relevant section from ANSII standard.