From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Empty String confusion; Positive and Natural Date: Tue, 30 Nov 2021 13:54:16 +0100 Organization: Adalog Message-ID: References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 30 Nov 2021 12:54:16 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="0e8ddcdce013eb64e6ce28584cebcb32"; logging-data="1960"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IMfVraNVr9bQAZFHrLswZ" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Cancel-Lock: sha1:Mum8RxH7/SC1H8JuGhZivxjBPsI= In-Reply-To: Content-Language: fr Xref: reader02.eternal-september.org comp.lang.ada:63173 List-Id: Le 30/11/2021 à 13:17, Kevin Chadwick a écrit : > I have a create function that returns a type RunOutput > > I always get range check failed even with a string of multiple characters. > > type RunOutput(LogLen, OutputLen : Natural) is record > LogStr : String(0..LogLen); > Output : String(0..OutputLen); > ... > end record; > > I did have the following which works, so long as the string is not empty > > type RunOutput(LogLen, OutputLen : Positive) is record > LogStr : String(1..LogLen); > Output : String(1..OutputLen); > ... > end record; > > > P.s. I am not using exceptions with messages for log strings because I would rather use features that work with the zero footprint runtime as much as possible, where it makes sense. > Since String is indexed by Positive (not Natural), the lower bound cannot be 0. OTOH, there is no check for bounds of empty arrays, therefore the following would work: type RunOutput(LogLen, OutputLen : Natural) is record LogStr : String(1..LogLen); Output : String(1..OutputLen); and you can have empty strings if Loglen or Outputlen is 0, without Constraint_Error. (It's precisely for that reason that there is no check of bounds of empty arrays). -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52 https://www.adalog.fr