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: g2news2.google.com!news3.google.com!feeder.news-service.com!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 12 Aug 2011 01:51:34 -0500 Newsgroups: comp.lang.c++,comp.lang.ada Subject: Re: Why use C++? From: Paavo Helde 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> Organization: PKI Message-ID: User-Agent: Xnews/5.04.25 Date: Fri, 12 Aug 2011 01:51:34 -0500 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-qJEcxWmwAkM/C5EzqeD+HksCdNs1uM5Nw9/QI/y47BuBD9eWNZoo5WzYStp41l3jqrLyepIbbg8VaNm!aw7sVlP5/v7nFd7HCzffNqAea0sxBiSAhjF2OfrIOGrzdP6J/pg12g6jPj8tKsfbSrIlljk1ghme!/HHeJSfE X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3592 Xref: g2news2.google.com comp.lang.c++:92599 comp.lang.ada:21525 Date: 2011-08-12T01:51:34-05:00 List-Id: "Jed" wrote in news:j22ddq$7pq$1@dont-email.me: > > "Randy Brukardt" wrote in message > news:j22c61$5lo$1@munin.nbi.dk... > >> Modular types are something altogether different (and in all honesty, >> rare enough that direct language support is of dubious value -- most of >> us supported adding them to Ada 95 simply because it was the only way >> to get any support for the largest unsigned integer type). >> > > Isn't the wrapping behavior just a consequence of wanting to get a > representation in which signed and unsigned integers can be easily > converted to each other? I.e., "they" didn't sit down and say, "let's > implement unsigned integers with wrapping behavior". Indeed, the 2's complement representation allows to use the same hardware instruction for implementing the signed and unsigned addition (ditto for subtraction). However, this means that the hardware will raise the overflow flag exactly in the same fashion, so it would be equally easy to detect the overflow. 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. Cheers Paavo