delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/01/22:48:57

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ' ^ '
Date: 2 Nov 1997 02:34:19 GMT
Organization: Oxford University, England
Lines: 27
Message-ID: <63gorb$80v$1@news.ox.ac.uk>
References: <621df9$cp9 AT camel12 DOT mindspring DOT com> <e5w#Ljv58GA DOT 248 AT upnetnews02 DOT moswest DOT msn DOT net>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Sat, 1 Nov 1997 14:07:07 -0500 in comp.os.msdos.djgpp Carolyn
Kelly-Pajot <dehacked72 AT hotmail DOT com> wrote:

: #include <iostream.h>
:
: void main()
  ^^^^
Yuck. The main function must, must, must return `int'. If you write
`void', this compiler silently changes it to `int' anyway. So using a
different return type is not only illegal, it also causes the compiler
to compile something different from what you write. It's far better to
have the compiler compile exactly what you write; so always define the
main function to return `int'. Also, put a return statement in the
function body. If you compile your code with `-Wall' (as everyone
should IMHO), these will be pointed out to you.

(I know you only wrote this quickly to demonstrate a point, but it's
bad to post incorrect code nevertheless; people who don't know better
might, in reading your helpful answer, think that defining `main' with
a void return type is valid code, which it isn't. If you don't care
in your own code, that's your choice, but when advising others I think
incorrect advice can be worse than no advice at all.)

-- 
Regards,

george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


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