delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/29/18:03:21

From: "M. Schulter" <mschulter AT value DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Begginer problems with C & DJGPP
Date: 29 Dec 1997 22:34:09 GMT
Organization: Value Net Internetwork Services Inc.
Lines: 49
Message-ID: <6898h1$ft9$2@vnetnews.value.net>
References: <682ti1$keq$1 AT svr-c-02 DOT core DOT theplanet DOT net> <34A579C8 DOT 6B72 AT cs DOT com> <34A7D31D DOT 434B5D15 AT IHateSpam DOT com>
NNTP-Posting-Host: value.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ryan McGee <rdm AT IHateSpam DOT com> wrote:
: why is useing void main() a bad idea?  I've heard that all over the place
: but nobody tells me why I shouldn't do that.  Does it have something to do
: with error checking?  What's going to check the return value of main?

Hello, there.

While some might argue that your question is not _strictly_ on topic, I
tend to conclude that the benefits to a DJGPP beginner of getting this
right from the start outweigh the slight extra bandwidth.

Basically, using

int main(void)

and returning 0 at the end of your program (assuming a normal exit)
provides vital information either for the operating system itself, or
possibly to other programs which could use this information.

Also, it is the correct way to go under the ANSI C standard, as opposed to
some of its _mis_interpretations published in certain books and
commentaries.

Following the correct approach means both that DOS will get the
appropriate error code upon exit, and that your code should be more
portable to other OSes. It's a good habit to get into, whether or not you
immediately run into a situation where it would make a difference.

May I add a bit of DJGPP culture here as a fair notice to a newcomer. We
constantly see newcomer programs posted here with void main -- an
unfortunate result of enthusiastic users who happen to get their hands on
the wrong books or tutorials first -- at least, the wrong books or
tutorials on this important point.

While technically one could argue that it's "outside the DJGPP charter,"
it's almost become a running joke, and lots of people feel that it's
on-topic enough to correct the newcomer.

As another person has correctly suggested, you can get more information on
this point in the C language FAQ, an excellent document for DJGPP users.
One of the advantages of using DJGPP is that you'll run into lots of
people who really know the ANSI C standard and have experience working
with various platforms.

Most respectfully,

Margo Schulter
mschulter AT value DOT net

- Raw text -


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