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: 103376,d679dd7e9c16805a X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Selective suppression of warnings --- gnat on GNU/Linux Date: Wed, 31 Dec 2008 09:55:46 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <7a6baa71-80e8-4f3a-80b6-34935bda2fc0@r10g2000prf.googlegroups.com> <42ffjg.s9b.ln@hunter.axlog.fr> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls4.std.com 1230735346 16246 192.74.137.71 (31 Dec 2008 14:55:46 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 31 Dec 2008 14:55:46 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:JUH6yhaNVxGTqVk3mN6HETvFCYw= Xref: g2news2.google.com comp.lang.ada:4122 Date: 2008-12-31T09:55:46-05:00 List-Id: Jean-Pierre Rosen writes: > Robert A Duff a �crit : >> 1. subtype T is Integer range A..B; >> 2. type T is new Integer range A..B; >> 3. type T is range A..B; >> [...] Option 3 is questionable, because of overflow semantics for >> intermediate >> results in expressions. In Pascal, if you say (X+Y)/2, it won't >> overflow if X+Y is in Integer, but not in A..B. Same is True in Ada for >> option 2, but not necessarily for option 3. > Oh no! Option 2 has exactly the same problem, you just hope that by > forcing your type to have the same number of bits as Integer (a type you > know nothing about), there will be enough room for your computations... > > If you are worried about overflows (and you use only additions), the > proper declarations are: > type Big_Enough is range A .. 2*B; > subtype T is Big_Enough range A .. B; > > Of course, if you compute more than single additions, a real analysis > has to be done to determine the bounds of Big_Enough. That's all true, if we're just talking about Ada. But we're talking about translating Pascal into Ada. I was making the implicit assumption that Pascal's Integer is the same as Ada's Integer, which is likely true. If that's true, then we must presume that the Pascal programmer already made sure that calculations won't overflow, so they won't overflow in Ada Integer, either. Or else there's a bug in the Pascal code, and we're going to translate that into the same bug in the Ada code. If you don't like the above assumption, then I'd say the correct translation is: type Pascal_Integer is range ...; subtype T is Pascal_Integer range A..B; where the rangs of Pascal_Integer is chosen to match the Pascal compiler -- obviously you have to know something about the Pascal compiler. Either way (whether we use Integer or a special Pascal_Integer), there's no need to analyze the program for overflow, and do things like the 2*B you suggest -- that's not the job of a Pascal-to-Ada translator! > By all means, please, let's get rid of Integer! I'm all for it. ;-) - Bob