[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: odd compiler behaviour?



On Sun, Mar 16, 2003 at 10:06:01PM +0000, Colin Watson wrote:
> I stand corrected, then. Although 'info libc' does say that (void) is OK
> for main() in ISO C.

Correct.  Two ISO C forms of main are:

  int main (void) { ... }  
  /* identical to: int main () { ... } */ 

or

  int main (int argc, char *argv[]) { ... }
  /* identical to: int main (int argc, char **argv) { ... } */


However:

  int main ();

and

  int main (void);

are not identical *declarations*.   But only crazy people who like to
call "main" recursively ever write declarations for it...

In non-conforming mode (the default), gcc will also accept "void main(...)"
and the three argument form that adds "char **envp"...

And then, there is the K&R form with implicit int return:

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

K&R is accepted but deprecated in all versions of ISO/ANSI C except the
implicit int return type is an error in C99.

(Now, back to your regularly scheduled program ...)

-- 
echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse



Reply to: