strings

Norman Diamond diamond at csl.sony.co.jp
Mon May 15 12:48:25 AEST 1989


I wrote:

>>It [null-terminated strings] seems intrinsically worse to me.

Doug Gwyn replied:

>I thought it was well known that each method (associated count vs.
>terminator) has advantages in some contexts and disadvantages in
>others.  Many interesting operations on strings are faster with null
>terminator values than when an associated count must be tested.  The
>main drawback to terminated strings is that the terminator value
>cannot be contained within the string.

Fine.  So in a language which does not specify how strings are
implemented, an implementation could be improved by using BOTH
a count and a null terminator.  This still is not possible in C.

>If you want counted strings, C makes it relatively easy to provide
>them for yourself.

Yes.  You throw away the C library (which I understand is part of the
proposed ANSI standard) and the language's definition of how strings
are represented, you define your own representation of strings, and
you implement your own library.  This is perfectly fine.  A strictly
conforming program is not required to use every feature or every
mis-feature of the standard; a program is allowed to be more strict.

Good luck porting other people's strictly conforming programs though.
They might use C strings.

Good luck persuading someone else to port your programs.

--
Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.co.jp at relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-implementing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?



More information about the Comp.lang.c mailing list