From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,98ad5b2a2cd88a53 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,98ad5b2a2cd88a53 X-Google-Attributes: gid103376,public From: Biju Thomas Subject: Re: Ada or C++ acting 'correctly' here? Date: 1999/02/27 Message-ID: <36D85A54.2A0E6283@ibm.net>#1/1 X-Deja-AN: 449384371 Content-Transfer-Encoding: 7bit References: <7b8c7u$sj1@drn.newsguy.com> <7b9i8l$6ql$1@ash.prod.itd.earthlink.net> X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset=us-ascii X-Complaints-To: postmaster@ibm.net X-Trace: 27 Feb 1999 20:40:01 GMT, 32.100.144.233 Organization: Home MIME-Version: 1.0 Reply-To: bijuthom@ibm.net Newsgroups: comp.lang.ada,comp.lang.c++ Date: 1999-02-27T00:00:00+00:00 List-Id: Claudius Proculus wrote: > > In article <7b8c7u$sj1@drn.newsguy.com>, bill@mooner wrote: > >compare these 2 little programs, do same thing, one in C++ > >and one in Ada. The C++ program compiles Ok, but result is > >negative, the Ada program refused to compile: > > > > > >---------------------------- > >#include > >int main() > >{ > > cout<<(500000000*7); > > return 0; > >} > >----------------------------- > >%g++ -Wall test_mult.cc > >%./a.out > >-794967296 > > > >(this is g++ 2.8.1) > > > > They are both the correct behavior. > No. The C++ compiler is non-conforming. The C++ standard says that if a constant expression cannot be represented in the target type, the program is ill-formed. (Chapter 5, paragraph 5.) A C++ compiler is required to issue a diagnostic message while compiling an ill-formed program. (It is *not* an undefined behaviour.) > However, this does illustrate one of the benefits of using Ada. Ada certainly will have benefits, but not on this one. -- Best regards, Biju Thomas