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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.133.88 with SMTP id h85mr4320797iod.90.1513579178397; Sun, 17 Dec 2017 22:39:38 -0800 (PST) X-Received: by 10.157.87.203 with SMTP id q11mr761336oti.8.1513579178292; Sun, 17 Dec 2017 22:39:38 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!g80no835063itg.0!news-out.google.com!s63ni1328itb.0!nntp.google.com!g80no835056itg.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 17 Dec 2017 22:39:37 -0800 (PST) In-Reply-To: <6bedbdee-ca7f-4d2a-83f9-6cc9c53d21cb@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:10a5:ee1:5dcc:4cb8; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:10a5:ee1:5dcc:4cb8 References: <6bedbdee-ca7f-4d2a-83f9-6cc9c53d21cb@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <3c367d8d-351e-4c72-b259-c04a5285d025@googlegroups.com> Subject: Re: how to do things like procedure foo(A: string) is bar: string := A; begin; ...;end; From: Robert Eachus Injection-Date: Mon, 18 Dec 2017 06:39:38 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:49511 Date: 2017-12-17T22:39:37-08:00 List-Id: On Saturday, December 16, 2017 at 3:56:45 PM UTC-5, Mehdi Saada wrote: > DATA being strings components of the records LEFT and RIGHT, is the expre= ssion (LEFT.DATA & RIGHT.DATA)'Range possible ? > I try to implement something like > procedure foo(A: string) is > bar: string :=3D A; > begin > ... > end; > but A'Length isn't known at compilation. In fact I want to use bar only l= ike a macro, to avoid puting things like LEFT.DATA & RIGHT.DATA everywhere = and not being able to use attributes (Range, length & co). There is no problem with your example. There is a potential (mental) gotch= a if you concatenate a character or a null string literal to the beginning = of another string literal. A bit of thinking should tell you that such str= ings begin at 1, not Integer'First, and the last is Left.Data'First + Right= .Data'Length. If your subprogram Foo has an unconstrained String parameter (yours does) t= hen the bounds of A are the bounds of the actual argument, and can be diffe= rent on every call. If you have a constrained String (i.e. String(6..15) o= r whatever) then inside Foo the bounds are those of the formal parameter. = If the LENGTHS of (constrained) formal and actual don't match, Constraint_E= rror will be raised. As I said, there is not a problem in Ada--but everyone will eventually run = into a couple of bugs because they unthinkingly assumed that the actual for= the unconstrained formal starts at 1. So now if you see something like: function Foo(S: String) return String is begin if S'Length < 80 then return "" & S; else... You will have a clue what is going on. ;-)