delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/10/12:53:35

Sender: crough45 AT amc DOT de
Message-Id: <97May10.184721gmt+0100.16645@internet01.amc.de>
Date: Sat, 10 May 1997 17:51:07 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: asu1 AT cornell DOT edu
Cc: djgpp AT delorie DOT com
Subject: Re: compile warning

A. Sinan Unur wrote:

> first, this is pure and simple C. in any case, void is not a valid
> return type for main. 

Incorrect.  Void is a perfectly good return type for main.

> main has to return an int.

No it doesn't.  It only needs to generate any specific exit value
if you will be using the result to test the state of the program
afterwards (like in make or with the batch ERRORLEVEL).  And even 
then it's perfectly valid to use exit(n) rather than return.  Since
many compilers complain if there is no return with a value from
a non-void function, if the program is known to always use exit()
or be non-terminating it is often better to declare main as void
to get rid of the warnings.

It may be considered, in some places, good /style/ to declare main
as int, but that's a long way from it being an absolute.

Even with -Wall -ansi -pedantic I can't get gcc to complain about
void main...

Chris

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019