www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/10/15:36:05

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: compile warning
Date: Sat, 10 May 1997 11:04:12 -0700
Organization: Alcyone Systems
Lines: 48
Message-ID: <3374B89C.52FC7701@alcyone.com>
References: <97May10.184721gmt+0100 DOT 16645 AT internet01 DOT amc DOT de>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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

Wrong.  ANSI C standard, section 5.1.2.2.1.

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

No; the standard dictates that main must conform to one of the following
two prototypes:

    int main(void);
    int main(int argc, char *argv[]);

> And even
> then it's perfectly valid to use exit(n) rather than return.

ANSI C 7.10.4.3.  Control is returned to the host environment, and
successful termination or unsuccessful termination is "returned."  This
means that from the point of view of a program-executing environment,
calling exit makes the program look like it returned from main.

> 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 an ANSI violation to have main return anything other than int,
even if your host environment doesn't do anything valuable with the return
values.

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

So?  Just because a compiler doesn't complain about something doesn't that
something ANSI C compliant.
-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
                      "The future / is right there."
                                 / Bill Moyers

- Raw text -


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