comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: Ada Idioms Progress Preview
Date: Mon, 13 Aug 2001 12:22:00 -0400
Date: 2001-08-13T16:22:02+00:00	[thread overview]
Message-ID: <9l8ura$bdd$1@nh.pace.co.uk> (raw)
In-Reply-To: umqr8ug55d9.fsf@maestro.clustra.com

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" <ohk@clustra.com> 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.
>






  reply	other threads:[~2001-08-13 16:22 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-03  4:16 Ada Idioms Progress Preview James Rogers
2001-08-03 19:45 ` Robert Dewar
2001-08-03 22:02   ` James Rogers
2001-08-06 22:33   ` Stanley R. Allen
2001-08-07  2:45     ` tmoran
2001-08-07 12:15       ` Larry Kilgallen
2001-08-07 13:26         ` Philip Anderson
2001-08-08  2:23         ` Robert Dewar
2001-08-08  5:58           ` Ehud Lamm
2001-08-08  2:19       ` Robert Dewar
2001-08-08 15:13         ` Ted Dennison
2001-08-08 18:03           ` tmoran
2001-08-09 20:36           ` Florian Weimer
2001-08-10 21:02         ` Jay Nabonne
2001-08-10 21:51           ` Larry Kilgallen
2001-08-13 14:19             ` Ted Dennison
2001-08-13 14:05           ` Ted Dennison
2001-08-13 14:19             ` Marin David Condic
2001-08-13 15:47             ` Ole-Hjalmar Kristensen
2001-08-13 16:22               ` Marin David Condic [this message]
2001-08-13 18:48               ` Larry Kilgallen
2001-08-14  7:05                 ` Ole-Hjalmar Kristensen
2001-08-13 20:20               ` James Rogers
2001-08-14  1:09                 ` Warren W. Gay VE3WWG
2001-08-14  6:15                   ` James Rogers
2001-08-14 14:03                     ` Warren W. Gay VE3WWG
2001-08-21  5:54                   ` C strings, was " David Thompson
2001-08-16 18:42                 ` Jay Nabonne
2001-08-17  1:25                   ` Robert Dewar
2001-08-13 21:47               ` Ted Dennison
2001-08-14  7:37                 ` Ole-Hjalmar Kristensen
2001-08-14 14:59                   ` Ted Dennison
2001-08-14 13:22                 ` Marin David Condic
2001-08-14 15:12                   ` Ted Dennison
2001-08-14 15:33                     ` Marin David Condic
2001-08-14  8:49               ` Lutz Donnerhacke
2001-08-14  9:38                 ` Ole-Hjalmar Kristensen
2001-08-14  9:54                   ` Lutz Donnerhacke
2001-08-14 14:51                     ` James Rogers
2001-08-14 16:44                   ` Darren New
2001-08-14  1:39             ` Slicing ( Ada Idioms Progress Preview ) Warren W. Gay VE3WWG
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox