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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4c86cf2332cbe682 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-13 11:29:29 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!Germany.EU.net!EU.net!chsun!mlma11.matrix.ch!user From: Mats.Weber@matrix.ch (Mats Weber) Subject: Re: Ada.strings.bounded problems? Message-ID: Sender: usenet@eunet.ch Organization: ELCA Matrix SA References: <3f3rl7$kts@watnews1.watson.ibm.com> Date: Fri, 13 Jan 1995 19:29:29 GMT Date: 1995-01-13T19:29:29+00:00 List-Id: In article <3f3rl7$kts@watnews1.watson.ibm.com>, ncohen@watson.ibm.com wrote: > There IS a way to implement bounded strings with the bound given as a > constraint, so simple that it is found in many introductory examples: > > package Bounded_Strings is > type Bounded_String (Max_Length: Positive) is private; > ... -- all sorts of useful operations > private > type Bounded_String (Max_Length: Positive) is > record > Current_Length : Natural := 0; > Text : String (1 .. Max_Length); > end record; > end Bounded_Strings; > > This approach is easily generalized to other kinds of arrays. The BIG problem with this approach is that testing two Bounded_Strings for equality is erroneous (Ada 83 terminology). In Ada 95, this would be a bounded error, but two bounded strings may compare different while being logically equal. The problem comes from the unused characters in Text beyond Max_Length. Mats