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,1552407353207252 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 30 Sep 2005 20:03:39 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: Subject: Re: Range constraints on subprogram parameters? Date: Fri, 30 Sep 2005 20:07:25 -0500 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4952.2800 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4952.2800 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-mmQSJ6vwJfG7UNTGLJCtBFXPAbPlDrWyhKddiduDCCfbY3evy6R6JwSUOvlJVpEzsYW9iZcV5hkFSHV!oOiABLyQh2q6o6eWsJoJC7BtPZ988zzlkWmuhhYVthGcMwuCP/ZsjObIc2YrDcUthhm4MS+dWenb X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net 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.32 Xref: g2news1.google.com comp.lang.ada:5319 Date: 2005-09-30T20:07:25-05:00 List-Id: "Jeffrey R. Carter" wrote in message news:yi4%e.5290$oc.213@newsread2.news.pas.earthlink.net... > Bobby D. Bryant wrote: > > Yes, that's what I was wanting. > > > > It occurs to me in retrospect that it would be problematic from a > > language design perspective, since it would be impossible to enforce > > at compile time. > > It doesn't have to be enforceable at compile time, since subtype constraints > don't have to be static: > > procedure Outer (Max : in Positive) is > subtype Num is Positive range 1 .. Max; > > procedure Inner (X : in Num) is > > is perfectly legal. > > It mostly depends on where the subprogram is declared compared to where the > constraints are known. Actually, Bobby was correct. The reason you can't have subtype constraints in a parameter declaration is because they aren't required to be static. The problem is one of conformance when you have separate specifications and bodies. If F is an integer-returning function that returns 1 the first time it is called, 2 the second tine, and so on, what is the range of the parameter P? procedure Ugh (P : in Integer range 0 .. F); -- F = 1. Obj : constant Integer := F; -- Call on F = 2. procedure Ugh (P : in Integer range 0 .. F) is -- F = 3. ... This is why Ada 200Y allows null exclusions in parameters: because they always have to be static. We talked a bit aboult allowing static constraints in subprogram parameter declarations, but didn't do it because that seemed even more arbitrary than not allowing them at all. Note that declaring the subtype explicitly (and separately) doesn't have this problem. Randy.