Re: "Pascal" vs C style strings

Dinko Tenev <>
Tue, 28 Jun 1994 17:36:07 GMT

          From comp.compilers

Related articles
Re: "Pascal" vs C style strings (Dinko Tenev) (1994-06-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Dinko Tenev <>
Keywords: Pascal, design
Organization: Compilers Central
Date: Tue, 28 Jun 1994 17:36:07 GMT

One might suggest that the label "Pascal-style" should be taken with a
grain of salt: I've only seen strings w/ length prepended in Turbo Pascal.
This kind of character strings implementation, although very popular, is
far from a Pascal standard; in fact, strings in Pascal are supposed to be
of a fixed size, stored in variables of type "array[...] of char", so
they're hardly worth to be considered against C style strings.

Anyway, to the point: the major advantage of null-terminated strings is
their simplicity and elegance - elegance, by the way, is THE thing about C
which makes it so popular; writability comes extra - so, I could hardly
believe that K&R would prefer the "Pascal-style" implementation, even if
they'd started on an 8086 machine; if their considerations on the issue
were purely pragmatic, they might as well have come up with something like
PL/I or Ada :->

As for this implementation's drawbacks:

[ You can't have the null character in the string's contents ]

You'd hardly ever need it there. Having binary data
stored in text strings is somewhat imprudent.

[ Length(s) takes O(n) ]

There's nothing in the world that would prevent you
from keeping the string's length, and maybe passing it
when needed. If something ever would, C wouldn't.

One has to keep in mind that C style strings were meant to be applicable
in general text processing, which they are. And then, they're somewhere
in the middle between minimality and comfort - minimality is boring, and
who needs comfort, so ASCIIZ strings are just about right! :->


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.