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: bobduff@world.std.com (Robert A Duff) Subject: Re: Equality operator overloading in ADA 83 Date: 1997/04/25 Message-ID: #1/1 X-Deja-AN: 237282091 References: <01bc4e9b$ac0e7fa0$72041dc2@lightning> <33692089.5794807@news.airmail.net> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1997-04-25T00:00:00+00:00 List-Id: In article , Matthew Heaney wrote: >But no heap is required: > > subtype Length_Range is Natural range 0 .. 132; > type String_Buffer (Length : Length_Range := 0) is > record > Buffer : String (1 .. Length); > end record; This is a recipe for disaster, IMHO. You'll end up with programs that work fine most of the time, but fail when they happen to trip over a file name longer than 132 characters (or a line in a file, or whatever it is you're using those strings for). Furthermore, it's not particularly efficient to copy around 132 characters all the time, when most of your strings are around 10 characters long. No, the heap is the right solution to true varying-length strings. Unfortunately, Ada 83 doesn't give you the tools needed to avoid storage leaks without breaking the abstraction. The tool needed is either garbage collection, or finalization and user-defined assignment. >But all of these very real problems were cleaned up in Ada 95. So you are >correct that string manipulation - in Ada 83 - can be a pain, but this is >NOT the case for Ada 95, nor are "Ada strings" somehow more inefficient. "More inefficient" than what? Than C's nul-terminated strings? Perhaps true, at least in many cases. But Ada strings *are* more inefficient than they *could* be. In particular, there's no way to fix the lower bound to 1, so the generated code has to carry around 8 bytes of dope, where 4 would suffice. And do a subtract to determine the length. Or carry 12 bytes, to avoid the subtract. Don't tell me to use a discriminated record, because then I lose all kinds of nice notations (like indexing, slicing, and string literals). - Bob