delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/11/22:04:33

From: leathm AT solwarra DOT gbrmpa DOT gov DOT au (Leath Muller)
Message-Id: <199705120201.MAA13250@solwarra.gbrmpa.gov.au>
Subject: Re: compile warning
To: crough45 AT amc DOT de (Chris Croughton)
Date: Mon, 12 May 1997 12:01:39 +1000 (EST)
Cc: asu1 AT cornell DOT edu, djgpp AT delorie DOT com
In-Reply-To: <97May10.184721gmt+0100.16645@internet01.amc.de> from "Chris Croughton" at May 10, 97 05:51:07 pm

> > 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.

Wrong wrong wrong... you must return int...
 
> > 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.

What if another program not written by yourself requires your program
to return a value, and you haven't written one, you are restricting
portability... no? You _must_ return a value, even if you don't see it
as obvious as to why...
 
> 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.

No, it is absolute.

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

So? There are probably a lot of things you can do that can cause problems
which don't pop up in the compiler... basically, if the ansi doc says
you should do it a certain way, then you should do it that way...

Leathal.

- Raw text -


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