Re: Pascal vs C style string ?

andrew@cee.hw.ac.uk (Andrew Dinn)
Tue, 28 Jun 1994 08:08:05 GMT

          From comp.compilers

Related articles
[4 earlier articles]
Re: Pascal vs C style string ? ddean@robadome.com (1994-06-27)
Re: Pascal vs C style string ? boehm@parc.xerox.com (1994-06-27)
Re: Pascal vs C style string ? nandu@cs.clemson.edu (1994-06-27)
Re: Pascal vs C style string ? eifrig@beanworld.cs.jhu.edu (1994-06-28)
Re: Pascal vs C style string ? monnier@di.epfl.ch (Stefan Monnier) (1994-06-28)
Re: Pascal vs C style string ? eru@tele.nokia.fi (Erkki Ruohtula) (1994-06-28)
Re: Pascal vs C style string ? andrew@cee.hw.ac.uk (1994-06-28)
Re: Pascal vs C style string ? jhallen@world.std.com (1994-06-28)
Re: Pascal vs C style string ? larryr@pa.dec.com) (1994-06-28)
Re: Pascal vs C style string ? boehm@parc.xerox.com (1994-06-28)
Re: Pascal vs C style string ? cjmchale@dsg.cs.tcd.ie (1994-06-29)
Re: Pascal vs C style string ? nandu@cs.clemson.edu (1994-06-29)
Re: Pascal vs C style string ? Theo.Norvell@comlab.oxford.ac.uk (1994-06-30)
[4 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: andrew@cee.hw.ac.uk (Andrew Dinn)
Keywords: C, Pascal, design
Organization: Dept of Comp and Elec Eng, Heriot-Watt University
References: 94-06-175 94-06-215
Date: Tue, 28 Jun 1994 08:08:05 GMT

guerin@IRO.UMontreal.CA:
> Is there some reasons to use string0 over length attributed string ??


Drew Dean <ddean@robadome.com> wrote:
>[counted strings can contain any byte values]


Jonathan Eifrig (eifrig@beanworld.cs.jhu.edu) wrote:
: True, but *character* strings should only contain valid
: *characters*. The real moral of the story is that you should be using
: a data representation appropriate to the data to be represented. :-)


: If you want to deal with arrays of bytes, you should deal with
: arrays of bytes. :-)


And herein lies the ultimate moral of this ragger shaggy tale. C strings
only contain a NUL at the end to stop string librray code dropping off the
end but, contrary to several previous statements, there is no reason why
`strings' (i.e. byte arrays) cannot contain zero bytes followed by other
useful data (and they don't need to be encoded e.g. by duplicating them
:-). The only requirement if the programmer wants to store NULs in his/her
`strings' is that the program keep track of the length by some other
means, either by allocating them with fixed length or by storing the
length with the address of the string.


If you compare the string and memory libraries you will see how to write
your printer driver. The appropriate data representation in C for byte
arrays is 'char * + int', not to be confused with 'NUL-terminated char *'.


Pascal merely differs from C in two respects: i) it requires the length of
strings/byte arrays to be fixed at compile time ii) there is no library of
string functions based around the *convention* that the interesting bytes
are the ones which come before the NUL. The limitation which Pascal
suffers and C does not is the former. The latter makes no odds
(construction of a Pascal library for NUL-terminated strings left as an
exercise for the reader).


Andrew Dinn
--


Post a followup to this message

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