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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,98ad5b2a2cd88a53 X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,98ad5b2a2cd88a53 X-Google-Attributes: gid109fba,public From: "Willliam V" Subject: Re: Ada or C++ acting 'correctly' here? Date: 1999/03/02 Message-ID: <7bg0pc$5a4$1@ffx2nh3.news.uu.net>#1/1 X-Deja-AN: 450263204 References: <7b8c7u$sj1@drn.newsguy.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 X-Complaints-To: news@ffx2nh3.news.uu.net X-Trace: ffx2nh3.news.uu.net 920356460 5444 199.173.190.27 (2 Mar 1999 06:34:20 GMT) Organization: UUNET NNTP-Posting-Date: 2 Mar 1999 06:34:20 GMT Newsgroups: comp.lang.ada,comp.lang.c++ Date: 1999-03-02T06:34:20+00:00 List-Id: 500000000*7 is a negative quantity. C++ prints out what you ask it to do. try unsigned long l = 500000000*7; cout << l; or even cout << ((unsigned long )500000000)*7); If Linux 'd make the unsigned long to be 64 bit, you Ada would have compiled fine. So the Ada compiler you are using is relying very heavily on the underlying C machinery. Don't be too fast to blame C or C++ Wil bill@mooner wrote in message <7b8c7u$sj1@drn.newsguy.com>... >Hello, > >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) > >---------------------------- >with Ada.Integer_Text_Io; use Ada.Integer_Text_Io; >procedure Test_Multi is > begin > Put( 500000000*7 ); > end Test_Multi; >----------------------------- >$gnatmake test_multi.adb >gcc -c test_multi.adb >test_multi.adb:6:18: value not in range of type "Standard.Integer" >test_multi.adb:6:18: static expression raises "Constraint_Error" >gnatmake: "test_multi.adb" compilation error > > >Now. Which would you consider the correct language behaviour? >(same machine, Pentium pro, Linux. > >Bill.