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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Substrings as argument to procedures/functions Date: Tue, 12 Apr 2016 11:01:35 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com> NNTP-Posting-Host: bqgfK7NL3xTHnr0WRaLl4g.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:30082 Date: 2016-04-12T11:01:35+02:00 List-Id: On 12/04/2016 10:25, reinkor wrote: > I believed that if a substring is an argument to a subroutine, > then its "range" would start at 1 (and not inherited from the calling program). > But this seems not to be the case. > > Given the following Ada source code: > > with Text_IO; > use Text_IO; > procedure t3 is > package Int_Io is new Text_IO.Integer_Io (Integer); > use Int_Io; > procedure string_test1(S : String) is > begin > New_Line; > Put(" In string_test1: "); > Put(S'First,4); > Put(S'Last,4); > end string_test1; > Str : String := "ABCDEF"; > begin > string_test1(Str); > string_test1(Str(3..5)); > end t3; > > The second call to "string_test1" gives: > > In string_test1: 3 5 > > (at least on my computer). > > Is this correct? And in case, is it "good" ? :-) Yes, it is good. Consider a program that uses an index to walk through a string/array. When you pass a substring of the string and an index into it (usually in-out) down to a subprogram, then the index remains valid. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de