Morris Dovey wrote:
> James Harris wrote:
>
>> I suppose the bit missing from what I said above is that the C
>> concept of a string being an array (of char) allows nowhere for
>> a length prefix. If it is an array of char then all elements
>> should be of type char. I suppose the libraries could just
>> ignore this requirement (could they?) but then would have to
>> agree on how many bytes made up the length and in what order
>> they existed. Hmm....
>
> The Stratus C compiler provides both BCPL and C strings. IIRC,
> the length component of the BCPL-PL/I style string is a 16-bit
> unsigned value.
>
> It does require additional library functions (as well as the
> expected conversions back and forth) - and is comparable to
> using both imperial and metric systems in a machine design
> (IMHO, _not_ a great idea).
>
> I felt that the existing C string implementation was easier to
> work with, but that may just have been a matter of being more
> used to it.
In general, the objections to C string format are due to:
1. The lack of an immediately available length.
2. Vulnerability to overwriting past storage end.
1. is greatly mitigated by the fact that strings are usually short,
and thus it is a trivial effort to extract the length, with usually
highly optimized code in strlen().
2. is the real bug-a-boo. Use of carefully crafted routines, such
as strlcpy and strlcat will virtually eliminate those problems.
Unfortunately, those routines are not present in standard C
libraries.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com


|