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, LOTS_OF_MONEY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6122265fe3a60a37 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-06 15:25:58 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.skycache.com!Cidera!netnews.com!isdnet!psinet-france!psiuk-f4!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: Some problems with string type(Exact String?) Date: Wed, 6 Jun 2001 18:08:41 -0400 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: <9fm9la$c93$1@nh.pace.co.uk> References: <3B1EE460.D08AD019@wanadoo.fr> <3B1E5BAA.49F1EF9B@amsjv.com> NNTP-Posting-Host: 136.170.200.133 X-Trace: nh.pace.co.uk 991865322 12579 136.170.200.133 (6 Jun 2001 22:08:42 GMT) X-Complaints-To: newsmaster@pace.co.uk NNTP-Posting-Date: 6 Jun 2001 22:08:42 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:8273 Date: 2001-06-06T22:08:42+00:00 List-Id: In Ada, a string is just an array of characters - the array bounds have to be fixed for an object of type String. The string you declare is thus always N elements big. This is true of C as well. Any arrays of characters you allocate have some fixed length for their lifetime. Referencing something outside of their length is not checked by C - hence instead of an exception, you get an error that may or may not kill the program on any given day of the week and when it dies mysteriously, you get to haul out your debugger. By *convention* (and ONLY by convention) when you have an array of char in C, you stick null characters into the unused portions and all string handling routines look for this as an indicator of the end of the string. You could just as easily write a bunch of string routines in Ada that depended on null termination. Its just that there are better ways. When using fixed length strings, remember that the attributes 'First, 'Last, 'Range, etc. apply to the *array* and not to the *content* of that array. If you want strings with more C-ish behavior look at the package Ada.Strings.Bounded. This is essentially a record with a string element of some maximum length and a current "length" element telling you where you stopped storing characters in it. Hence they have a maximum size, but will give you subprograms to work with the content. If you want to avoid the whole mess - go to Ada.Strings.Unbounded and use that. This will have some version of dynamic memory allocation to satisfy the current size of whatever you store there. Its more expensive time-wise, but the size is always whatever the contents is. You *could* do what you suggest as far as padding - but in my experience, its just a lot easier to convert anything of type String into something of type Unbounded_String and use all the stuff you have in Ada.Strings.Unbounded to manipulate the contents. 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/ "McDoobie" wrote in message news:lowT6.40598$DG1.6446489@news1.rdc1.mi.home.com... > > Alright, so in this example, the string has to be EXACTLY 20 characters. > > Now, in a couple other languages I've used, the string can be String<20 > characters but not 20 understand correctly, a string (or more appropriately the elements of an > ARRAY) have to precisely match the declared bounds of the array. Yes, no? > > I'm currently reading through the "Arrays and Records" chapter of > "Programming in Ada95" by Barnes. It's throwing alot of information at me, > and I'm hitting a couple kinks in digesting it all. But from what I can > glean, in Ada95 arrays are fixed. Unlike C where I could go less than but > not greater than the bounds of the array. My first hunch on the way to > work with this strictness(or so it seems) would be keep count of the > number of elements (characters of a string, numbers, whatever) going into > the array, and then pad the rest of the array with with NULLs or something > similar when there is no more information to add to the array. > > Am I thinking along the right track here? Or am I missing something > important? > > McDoobie chris@dont.spam.me