From -675187613382244626
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f78e5,314ebdf2ff957e27
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-04-15 17:01:47 PST
Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: kanze@gabi-soft.de (James Kanze)
Newsgroups: comp.std.c++
Subject: Re: Why int main()?
Date: Wed, 16 Apr 2003 00:01:47 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 56
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <d6651fb6.0304150056.50de7758@posting.google.com>
References: <Qbvla.955$5Z2.28625@newsfep1-win.server.ntli.net> <1050087548.757301@hqnntp01.autodesk.com> <i1Fla.21842$eo4.9547@fe10.atl2.webusenet.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1050451307 23641 10.0.0.1 (16 Apr 2003 00:01:47 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Wed, 16 Apr 2003 00:01:47 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 195aMz-000699-00
	for mail2news@news.news.demon.net; Wed, 16 Apr 2003 00:01:46 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id KAA11202; Wed, 16 Apr 2003 10:01:41 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 15 Apr 2003 08:56:46 GMT
X-Spam-Status: No, hits=-8.1 required=5.0
	tests=MAILTO_TO_SPAM_ADDR,NOSPAM_INC,QUOTED_EMAIL_TEXT,
	      REFERENCES,SPAM_PHRASE_01_02
	version=2.41
Xref: archiver1.google.com comp.std.c++:18765

ron@sensor.com ("Ron Natalie") wrote in message
news:<i1Fla.21842$eo4.9547@fe10.atl2.webusenet.com>...
> ""Chris Putnam"" <nospam42@attbi.com> wrote in message
> news:1050087548.757301@hqnntp01.autodesk.com...

> > In my experience, compilers that accept the void main() signature do
> > so by providing a wrapper function to match whatever signature the
> > OS requires.

> Not in my experience.  In my experience it is because the way the
> subroutine linkage works, you can get away with mixing up void and int
> returns.  Typically an int return is just a value in one of the
> general purpose registers so the only difference is the setting or
> omitting setting a value in the register.

> It's just sheer luck that it works.   

That and the fact that compiler writers don't like unnecessarily
breaking user code, even if the code is wrong.

> Try this:

>     struct {
>         char x[100];
>     } main() {
>      }

> and see what happens.

Works on my machine (Sun Sparc, Solaris, gcc 3.2.2 and Sun CC):-).
After I'd modified it so that the type wasn't defined in the return
value, of course.

With gcc, I had to compile it as C.  G++ won't accept a return type
other than int.  (Sun CC warns about an anachronism.  I don't know when
they thought this was legal.)

If I add a return statement with a value, it core dumps.  And I suspect
that on Intel processors, trying to use argc and argv in main will get
you into trouble as well.  But your example works.  (I know what you
were trying to say, and agree 100%.  It's just that just saying try this
is a dangerous way to point it out, unless you're sure that it will fail
on all implementations.)

--
James Kanze             GABI Software             mailto:kanze@gabi-soft.fr
Conseils en informatique orient�e objet/
                           Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, T�l. : +33 (0)1 30 23 45 16

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



