www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/05/19:03:19

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: void main ?
Date: Sat, 05 Jul 1997 16:00:56 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 47
Message-ID: <33BE6FB8.4BC6@cs.com>
References: <97Jul5.152902gmt+0100 DOT 16642 AT internet01 DOT amc DOT de>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp103.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Chris Croughton wrote:
> 
> There is a lot of code which does not need the return
> value of main ever, because main should never return.
> This includes all embedded software (mobile phones being
> the most ubiquitous example, since all phone software
> I've seen is written in C/C++).

Embedded software is a special case of C/C++ and may not have any
applicability to the general standard.  How many times have you written
a program to run a mobile phone?

> The only case where
> there's likely to be unexpected action on the return code
> is if it's called from a makefile, and the code most
> people write is unlikely to be called like that (ever
> seen a game called from a makefile?).  If a person is
> writing code for use with make or shell scripts which
> test the return value then it's up to them to make it
> return something sensible.  However, just forcing a
> return of some kind doesn't make the value meaningful...

Sorry, but you're wrong.  It is a generally recognized convention that
most programs should return a zero exit code to indicate that they ran
successfully.  A non-zero exit code is usually some form of error
condition.  Some programs obviously use the exit code for other things
(DOS 'choice' as an example).  But I always write my programs using that
convention, on the assumption that somebody some day may decide to
examine the exit code to see what happened.  This is called good
programming.

Lazy programmers, OTOH, will do anything they please, and nobody is
going to stop them.  Just because their code might not _always_ work
doesn't mean they have to go to the incredibly strenuous effort of
typing a return statement.  Nobody is going to tell them what they can
and can't do.  Then they get hired by Microsoft... and look what
happens.

It's hardly worth the fuss you're making over it.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Sin lies only in hurting other      |
|       aka Fighteer I       | people unnecessarily.  All other     |
|   mailto:fighteer AT cs DOT com   | 'sins' are invented nonsense."       |
| http://www.cs.com/fighteer |                 - Lazarus Long       |
---------------------------------------------------------------------

- Raw text -


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