From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Lower bounds of Strings Date: Tue, 5 Jan 2021 13:32:15 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <1cc09f04-98f2-4ef3-ac84-9a9ca5aa3fd5n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 5 Jan 2021 12:32:15 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="acc6d857b2474373846ef61bab0e87f9"; logging-data="31379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NNJJcXbDHkIN/PoNqb7K96avZf03yqbA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 Cancel-Lock: sha1:35JmUvyKZx6j8kGboFVo8pPnlYM= In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:61039 List-Id: On 1/5/21 12:57 PM, Dmitry A. Kazakov wrote: > > This is a constraint, a meaningless and dangerous one: > >    procedure Foo (X : Mono_String); >    S : String := "abcdefgh"; > begin >    Foo (S (2..S'Last)); -- Boom! Constraint_Error Surely the slice would slide, as it does in with Ada.Text_IO; procedure Slider is subtype S7 is String (1 .. 7); procedure Foo (X : in S7); procedure Foo (X : in S7) is -- Empty begin -- Foo Ada.Text_IO.Put (Item => X (7) ); Ada.Text_IO.New_Line; end Foo; S : constant String := "abcdefgh"; begin -- Slider Foo (X => S (2 .. 8) ); end Slider; ~/Code$ gnatmake -gnatan -gnato2 -O2 -fstack-check slider.adb x86_64-linux-gnu-gcc-9 -c -gnatan -gnato2 -O2 -fstack-check slider.adb x86_64-linux-gnu-gnatbind-9 -x slider.ali x86_64-linux-gnu-gnatlink-9 slider.ali -O2 -fstack-check ~/Code$ ./slider h -- Jeff Carter "I'm a vicious jungle beast!" Play It Again, Sam 131