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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no 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-13 09:53:41 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeeds.belnet.be!news.belnet.be!psinet-eu-nl!psiuk-p4!uknet!psiuk-n!news.pace.co.uk!nh.pace.co.uk!not-for-mail From: "Marin David Condic" Newsgroups: comp.lang.ada Subject: Re: Ada Idioms Progress Preview Date: Mon, 13 Aug 2001 12:22:00 -0400 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: <9l8ura$bdd$1@nh.pace.co.uk> References: <3B6F1B2F.4FC3C833@gsde.hou.us.ray.com> <5ee5b646.0108071819.6e84e33d@posting.google.com> <3_Xc7.45$NM5.84779@news.pacbell.net> NNTP-Posting-Host: dhcp-200-133.miami.pace.co.uk X-Trace: nh.pace.co.uk 997719722 11693 136.170.200.133 (13 Aug 2001 16:22:02 GMT) X-Complaints-To: newsmaster@news.cam.pace.co.uk NNTP-Posting-Date: 13 Aug 2001 16:22:02 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:11857 Date: 2001-08-13T16:22:02+00:00 List-Id: I look at it as a case of "You can pay me now or pay me later". The static array business is true of both languages since both allocate a fixed size array to hold a string of some indeterminate length <= the size of the array. In C the "convention" is to stick a null immediately after the last valid character, but nothing especially enforces this. I used to rely on the last-non-blank character in Ada83 to determine where the end of the valid string was (Then use slices, etc, for manipulation.) In either case, you have to search the string for the character whenever you need to know where it ends - thus making it pay to keep that info around. So building a custom fixed-max-length string in Ada is pretty trivial. There you calculate the last valid character at assignment and keep that info around for all subsequent operations. I'd done that as well - saving the processing time at the expense of having to work with a non-language defined construct with some inconvenience. (Not too much, but some.) You paid once up front to find the length, then that was that. You could do the same in C/C++ with a struct or a class - albeit with less checking - but its probably about a wash as to which would require more effort. Nowadays with Ada95 and Ada.Strings.Bounded and Ada.Strings.Unbounded, its a whole different ballgame. I usually recommend just using Ada.Strings.Unbounded because most of the time its easier and the penalty is unimportant in most apps. I'd even recommend telling newcomers to start right there and forget about fixed length strings except for two problems: You need to understand fixed strings to deal with Ada's syntax & semantics and you need fixed strings for lots of predefined packages like Text_IO. (Maybe Ada0x can make it possible to use just Unbounded strings? At least define parallel packages to Text_IO for them.) MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "Ole-Hjalmar Kristensen" wrote in message news:umqr8ug55d9.fsf@maestro.clustra.com... > > 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. > So, in a sense a C string is more self-describing than a plain Ada > string. > Of course, as soon as you call a procedure, you can use a slice, but > you still need the actual length to decide which slice. > > On the balance, I would rather have Ada strings. >