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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 109fba,cd8ed9115942852f X-Google-NewGroupId: yes X-Google-Thread: 103376,b92b95c9b5585075 X-Google-NewGroupId: yes X-Google-Attributes: gid4f1905883f,gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!feeder.news-service.com!news.osn.de!diablo2.news.osn.de!news.belwue.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 12 Aug 2011 09:41:34 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110613 Thunderbird/3.1.11 MIME-Version: 1.0 Newsgroups: comp.lang.c++,comp.lang.ada Subject: Re: Why use C++? References: <1e292299-2cbe-4443-86f3-b19b8af50fff@c29g2000yqd.googlegroups.com> <1fd0cc9b-859d-428e-b68a-11e34de84225@gz10g2000vbb.googlegroups.com> <9ag33sFmuaU1@mid.individual.net> <1d8wyhvpcmpkd.ggiui9vebmtl.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4e44d92f$0$7617$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 12 Aug 2011 09:41:35 CEST NNTP-Posting-Host: 44c9002e.newsspool1.arcor-online.net X-Trace: DXC=DJfihJR;B_cic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbZ4`Yna[0]:nnc\616M64>jLh>_cHTX3jmmd@@iJoj1ok X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.c++:82840 comp.lang.ada:20556 Date: 2011-08-12T09:41:35+02:00 List-Id: On 12.08.11 08:51, Paavo Helde wrote: > I guess that they were instead thinking about intermediate results. As > the wrap-around point (zero) is very close to the common usage range of > unsigned integers, it may well happen that in a complex arithmetic > expression a temporary intermediate result may fall below zero whereas > the final result will be OK again. This would in effect mean that the > addition-subtraction operations would lose the associativity property, > which would cause some headaches. E.g. the programmer should always use > parens for indicating the relative order of addition and subtraction, > e.g. a+(b-c) and take care that no intermediate result would overflow. As > the common C/C++ implementations do not bother to check overflow even for > the signed types, this would just mean that there would be a lot more of > formally undefined behavior which seems to work as expected on a lot of > hardware. So, instead of introducing a lot of UB they chose to make > things like a+b-c legal by a simple trick of declaring the unsigned types > wrap-around. > > Yes, Ada could have been wiser, I'm sorry to hear this is not the case. Sort of; Ada does have a number of definitions around overflow and when overflow matters, when in intermediate results. 1. with System; 2. procedure ovfl is 3. type I is range 1 .. System.MAX_INT; 4. r, a, b, c: I; 5. begin 6. a := 1; 7. b := I'Last; 8. c := 2; 9. r := a + b - c; -- overflow | >>> warning: value not in range of type "I" defined at line 3 >>> warning: "Constraint_Error" will be raised at run time 10. r := a + (b - c); -- o.K. 11. r := (a + b) - c; -- overflow | >>> warning: value not in range of type "I" defined at line 3 >>> warning: "Constraint_Error" will be raised at run time 12. end ovfl; $ ./ovfl raised CONSTRAINT_ERROR : ovfl.adb:9 overflow check failed $