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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45b47ecb995e7a3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-14 00:37:43 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!148.122.208.68!news2.oke.nextra.no!nextra.com!news1.oke.nextra.no.POSTED!not-for-mail Sender: ohk@maestro.clustra.com Newsgroups: comp.lang.ada Subject: Re: Ada Idioms Progress Preview References: <3B6F1B2F.4FC3C833@gsde.hou.us.ray.com> <5ee5b646.0108071819.6e84e33d@posting.google.com> <3_Xc7.45$NM5.84779@news.pacbell.net> From: Ole-Hjalmar Kristensen Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 194.143.59.98 X-Complaints-To: news-abuse@nextra.no NNTP-Posting-Date: Tue, 14 Aug 2001 09:36:59 MET DST Organization: Nextra Public Access X-Trace: readme.online.no 997774619 194.143.59.98 Date: 14 Aug 2001 09:37:32 +0200 Xref: archiver1.google.com comp.lang.ada:11893 Date: 2001-08-14T09:37:32+02:00 List-Id: Ted Dennison writes: > In article , Ole-Hjalmar Kristensen says... > >One thing which can be said in favour of having a terminator character > >is that it frees you from having to store the length explicitly. The > >length of a string is usually different from the size of the array > >used to store the string. > > It frees you from that problem in *some* cases. I find that most of the time I > don't change the string, so I can declare it perfectly sized. When you do that, > you are not storing the length explicitly, but rather implicitly in the array > bounds. As others have mentioned, you also don't have to iterate through every > valid data element to derive this piece of implicit information like you do with > C. Thus perfectly-sized Ada strings give you the best of both worlds. > But you usually don't need to know the length of the string, precisely because it has a sentinel value at the end :-) Perfectly-sized C string are no problems either: char x[] = "a perfect string"; I was thinking of the case where you cannot statically allocate a perfectly sized string, which pops up whenever you have to get variable sized strings from somewhere, as you describe below. Btw., I'm not saying that C strings are superior in general or trying to start a war, just that there are cases when using a sentinel value makes sense. > Unfortunately, the most notable exception to this is in reading data from > Text_IO, which is also one of the first things a newbie will want to do with Ada > strings. :-( > > --- > T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html > home email - mailto:dennison@telepath.com -- Kabelsalat ist gesund. Ole-Hj. Kristensen