comp.lang.ada
 help / color / mirror / Atom feed
From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: Empty String confusion; Positive and Natural
Date: Tue, 30 Nov 2021 13:54:16 +0100	[thread overview]
Message-ID: <so56to$1t8$1@dont-email.me> (raw)
In-Reply-To: <eac0b8bd-7f64-4909-b0d3-7730bc86a1efn@googlegroups.com>

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

  reply	other threads:[~2021-11-30 12:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 17:34 Empty String confusion; Positive and Natural Kevin Chadwick
2021-11-29 18:05 ` Jeffrey R.Carter
2021-11-29 19:19 ` Niklas Holsti
2021-11-29 22:50   ` Kevin Chadwick
2021-11-30  8:29     ` Simon Wright
2021-11-30  8:34     ` Niklas Holsti
2021-11-30 10:00     ` Jeffrey R.Carter
2021-11-30 12:17       ` Kevin Chadwick
2021-11-30 12:54         ` J-P. Rosen [this message]
2021-11-30 13:12           ` Kevin Chadwick
2021-11-30  7:40 ` ldries46
2021-11-30  8:21   ` Simon Wright
2021-11-30 12:39     ` ldries46
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox