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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c3a7c1845ec5caf9 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Equality operator overloading in ADA 83 Date: 1997/04/22 Message-ID: #1/1 X-Deja-AN: 236816819 References: <01bc4e9b$ac0e7fa0$72041dc2@lightning> <335CAEFE.35DC@elca-matrix.ch> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-04-22T00:00:00+00:00 List-Id: In article <335CAEFE.35DC@elca-matrix.ch>, Mats.Weber@elca-matrix.ch wrote: >> It took me a while to realize that, yes, even for types (without access >> objects) that have a physical length greater than the logical length, you >> can make the predefined equality work. This is true even for Ada 83, so >> you may be able to apply this technique to your problem. > >Yes, but the performance penalty is pretty big and it's hard to find the >bug if you forget the padding just once. What are you saying? That one should stick with the full-type-tagged technique, and not use the pad-with-extra-characters technique? The performance penalty is nothing compared to the fact that equality doesn't work. What's more important, program correctness or efficiency? > >GNAT 3.09 would fail, I just chacked: there is no padding of strings >shorter than the max length. Making Max_Length a discriminant of a >subcomponent of Bounded_String would solve the problem, probably better >(at least cleaner) than padding with nulls. But of course that solution would have a performance penalty too, right? type Bounded_String is private; private subtype Length_Range is Natural range 0 .. Max_Length; type Bounded_String (Length : Length_Range := 0) is record Buffer : String (1 .. Length); end record; end Bounded_Strings; If I want to append characters to my string, that means I have to change the value of the discriminant, and therefore must use aggregate assignment: procedure Append (Str : String; To : in out Bounded_String) is begin To := (Length => To.Length + Str'Length, Buffer => To.Buffer & Str); end Append; Without the (hidden) discriminant, I can just append the string to what's already there: procedure Append (Str : String; To : in out Bounded_String) is begin To.Buffer (To.Length + 1 .. To.Length + Str'Length) := Str; To.Length := To.Length + Str'Length; end Append; N'est-ce pas? Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271