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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4ff929aa5c2b2834 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed-0.progon.net!progon.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ranges and (non)static constraints Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1pqs0gcno5o2t.1195tm9yap28b.dlg@40tude.net> Date: Fri, 17 Nov 2006 10:08:48 +0100 Message-ID: NNTP-Posting-Date: 17 Nov 2006 10:08:48 CET NNTP-Posting-Host: 5fae7eac.newsspool4.arcor-online.net X-Trace: DXC=j5_8^>EEkC3TQL:hoD@>T?4IUKiZI^b4jMWE; X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7519 Date: 2006-11-17T10:08:48+01:00 List-Id: On Thu, 16 Nov 2006 18:18:47 +0100, Jean-Pierre Rosen wrote: > Dmitry A. Kazakov a �crit : >> On Thu, 16 Nov 2006 12:02:15 +0100, Maciej Sobczak wrote: >> >>> type T is range 1 .. N; >>> type U is new Integer range 1 .. M; >>> >>> N must be static, but M does not have to. >>> Why and what is the real difference between T and U? >> >> Informally, the second is an abbreviation for: >> >> type is new Integer; >> subtype U is range 1..M; >> >> so "range" refers to a subtype. On the contrary, in the first, "range" >> refers a type. So the difference. >> >> Is it real? I don't think so. > > Sorry, but there is a huge difference. With U, the range cannot be > outside the range of Integer, under penalty of Constraint_Error. T is > valid as long as the compiler offers a big enough integer type, and if > it doesn't, it won't compile. > > Actually, the second form should never be used: you are relying on > Integer, a non-portable type that plays absolutely (or almost) no > special role in Ada. Why derive from Integer, rather than from > Long_Integer, or anything else? I almost agree with this. However, unfortunately Ada does not require legality of type T range 1..N; for any N, as it IMO should [*]. So the argument about portability becomes a bit shaky. In fact it is only more portable than the second. However, the second is definitely tasteless. But is this difference "real"? > If you want dynamic bounds, remember that anything "dynamic" has to have > an upper limit at some point. It is thus better to write: > > type Biggest_T is range 1 .. Absolute_Max_Expectable_Value; > subtype T is Biggest_T range 1 .. N; Well, this is nice in theory, which I strongly support. But this theory applies only to application software, where Absolute_Max_Expectable_Value is determinable from the problem space. When developing portable libraries, and Ada is one of the best choices there, isn't it? Then the upper bound often becomes indeterminable. So people are forced to use [new] Integer. ARM does this as well by defining the type String based on Integer. Only in generics we have a choice to say: type T is range <>; This shouldn't be so. It is IMO a language defect. ------------- * OK, there still remains a limitation on the biggest universal integer a compiler can swallow, but it is a different dimension. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de