Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: NUL to term...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 24928 of 28006
Post > Topic >>

Re: NUL to terminate strings

by CBFalconer <cbfalconer@[EMAIL PROTECTED] > Mar 10, 2008 at 05:35 PM

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
 




 2 Posts in Topic:
Re: NUL to terminate strings
CBFalconer <cbfalconer  2008-03-10 17:35:16 
Re: NUL to terminate strings
rlb@[EMAIL PROTECTED] (R  2008-03-14 09:28:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:05:42 CST 2008.