On 2005-04-18, Dave Thompson <david.thompson1@[EMAIL PROTECTED]
> wrote:
> On Fri, 8 Apr 2005 20:08:40 +0000 (UTC), Marco van de Voort
(A "Thompson" answering on a C question from ATT. Hmm, ahh phew, the
firstname is wrong:-)
>> > The language C/C++ does not have string functions either, to this
day.
>>
> C has (since well before C89) and C++ inherits, functions for
> null-terminated strings. Technically these are in the standard library
> and not the core language syntax, except for literals, if that's the
> distinction you're making,
Correct. That was the distinction that I was making. Of course being
in the standard library matters, but the bolted-on feeling remains.
> but as they are standard they are
> officially part of the language(s). Null-terminated has its
> limitations and problems as already discussed elsethread, but they are
> strings and are usable for most purposes.
IMHO not, not after you have used anything better. They are complicated
and
laborintensive to use, and dangerous IMHO.
That's not to say that string types don't have problems (temp variables
and
excessive copying in some rare scenarario's, IIRC Chuck gave the typical
recursion example though that is easily worked around), but I'll take it
every time, since with nearly all stringtypes, you can always fall back to
a
string<-> array of char conversion if it e.g. is time critical, or. Or
pointer to array of char.
The delphi ansistring stringtype is quite nice, since it eases this
aspect:
- the stringtype identifier contains a pointer to the array
- the size, ref count and allocation size is maintained at negative
offsets
to p^
- the array of char is null terminated, _but_ the string can contain null
chars too.
These properties make it possible to pass the string directly to a C (
const
char *) type of parameter without conversion. Only danger is that strings
with null chars will be prematurely truncated.
I'm not really deep into the C++ template stringtypes, just heard there
were
some more advanced possibilities with it. Still have to research it, so
I'll
refrain from more comment on that.


|