From 7402070745824694845
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,a7bb6560624ae2c1
X-Google-Attributes: gidf78e5,public
From: bruce.wheeler@siemens.at (Bruce Wheeler)
Subject: Re: More M$ Not Conforming points...
Date: 1999/08/25
Message-ID: <37c3beb7.9137699@news.sie.siemens.at>#1/1
X-Deja-AN: 517134801
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <7ps1sg$dev$1@nnrp1.deja.com> <7pu4es$1mv3$1@news.hal-pc.org>
X-Original-Date: Wed, 25 Aug 1999 10:22:10 GMT
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 935608056 4408 128.250.29.17 (25 Aug 1999 19:07:36 GMT)
Organization: Siemens AG Austria
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAN8Q+0uEDnX0m9pzZAQF55gGAnxAcMt+a0mRzvGDCC+EpJ2pCYTHPkY7B /XqjGgMSjCh3fmpxwmTNm9UMk1gOuc3c =V1fg
NNTP-Posting-Date: 25 Aug 1999 19:07:36 GMT
Newsgroups: comp.std.c++

On 24 Aug 99 20:53:22 GMT, "Greg Brewer" <nospam.gregb@hal-pc.org> wrote:

><whbloodworth@my-deja.com> wrote in message
>news:7ps1sg$dev$1@nnrp1.deja.com...
>
>> Also, M$ will warn the developer if he/she does not return a value from
>> main...which I can live with despite the fact that the C++ standard also
>> states that main implicitly returns 0 if not specified.  The problem is
>> with their warning.  Given the following:
>>
>> int main (void) { }
>> VC++ produces the following warning:
>> warning C4508: 'main' : function should return a value; 'void' return
>> type assumed
>>
>> "void return type assumed" ???? What ? void assumed?
>
>This warning is no different than any other function without a return.  I
>think you will find that if you change it to
>   void main(void) {}
>it will compile without any complaints.
>
>Greg Brewer

This warning is quite different from all other functions without return
values. See below (3.6.5). As commented by W.Bloodworth, VC++ is warning
about well-defined legal C++. I don't know if it will return 0 as required
by the standard, but it indicates that it will not (void type assumed).

If you change it to void main(void) {}, as you suggest, you no longer have
a valid ISO C++ program. (3.6.2 - It shall have a return type of type int).

(from the C++ Standard)
3.6.1  Main function

1 A  program  shall  contain a global function called main, which is the
  designated start of the program.  It is implementation-defined whether
  a  program  in a freestanding environment is required to define a main
  function.
...

2 An implementation shall not predefine the main function.   This  func-
  tion  shall  not  be  overloaded.  It shall have a return type of type
  int, but otherwise its type is implementation-defined.  All  implemen-
  tations shall allow both of the following definitions of main:
          int main() { /* ... */ }
  and
          int main(int argc, char* argv[]) { /* ... */ }
...

5 A return statement in main has the effect of leaving the main function
  (destroying  any  objects with automatic storage duration) and calling
  exit with the return value as the argument.  If  control  reaches  the
  end  of  main  without  encountering a return statement, the effect is
  that of executing
          return 0;

Regards,
Bruce Wheeler
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



