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 > Languages Misc > Re: NUL to term...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 39 of 61 Topic 1118 of 1217
Post > Topic >>

Re: NUL to terminate strings; was reinventing ASCII?

by James Harris <james.harris.1@[EMAIL PROTECTED] > Mar 10, 2008 at 08:45 AM

On 10 Mar, 12:13, Ben Bacarisse <ben.use...@[EMAIL PROTECTED]
> wrote:
> James Harris <james.harri...@[EMAIL PROTECTED]
> writes:
> > On 8 Mar, 17:22, Ben Bacarisse <ben.use...@[EMAIL PROTECTED]
> wrote:
> > ...
> >> So they need a terminating character unless they are defined some
> >> other way?  Surely the question was why were they not defined in one
> >> of these other ways?
>
> > Yes, I mean that to allow C strings to be defined as they are by a
> > single pointer requires there to be a terminating character of some
> > sort.
>
> But this is not true -- at least not literally true.  In BCPL strings
> were represented by a single pointer, but that pointer was to a
> length.  I am sure you are not unaware of this kind of representation,
> I just think you are over-cooking the argument to come up with
> "requires there to be a terminating character".  I see no such
> requirement -- it could have been different.
>
> I suspect I am reading more into your statement than you intended.

I see your point and appreciate being made to think this through more
clearly. 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....

I was comparing this with the definition of a string as a tuple of
(address, length) where BOTH elements are passed as parameters - i.e.
a single reference to the string embeds both parameters or expects
both as arguments. As far as I can see tuples of this sort cannot be
used in C.

The remaining option (I think there are just these three primary
options for strings but would welcome correction) is to store
(address, length) separately and point to it. It's not as flexible as
the tuple option above and not as simple as C's string handling. I
guess it could have been used but maybe the following comment from the
paper you referred to above helps explain why C went the way it did:

"
Problems became evident when I tried to extend the type notation,
especially to add structured (record) types. Structures, it seemed,
should map in an intuitive way onto memory in the machine, but in a
structure containing an array, there was no good place to stash the
pointer containing the base of the array, nor any convenient way to
arrange that it be initialized. For example, the directory entries of
early Unix systems might be described in C as

    struct {
    	int	inumber;
    	char	name[14];
    };

I wanted the structure not merely to characterize an abstract object
but also to describe a collection of bits that might be read from a
directory. Where could the compiler hide the pointer to name that the
semantics demanded? Even if structures were thought of more
abstractly, and the space for pointers could be hidden somehow, how
could I handle the technical problem of properly initializing these
pointers when allocating a complicated object, perhaps one that
specified structures containing arrays containing structures to
arbitrary depth?

The solution constituted the crucial jump in the evolutionary chain
between typeless BCPL and typed C. It eliminated the materialization
of the pointer in storage, and instead caused the creation of the
pointer when the array name is mentioned in an expression. The rule,
which survives in today's C, is that values of array type are
converted, when they appear in expressions, into pointers to the first
of the objects making up the array.
"
 




 61 Posts in Topic:
reinventing ASCII?
wildhalcyon <wild.halc  2008-03-03 05:56:01 
Re: reinventing ASCII?
"cr88192" <c  2008-03-04 05:35:03 
Re: reinventing ASCII?
"Rod Pemberton"  2008-03-03 15:13:13 
Re: reinventing ASCII?
Jacko <jackokring@[EMA  2008-03-03 12:58:14 
Re: reinventing ASCII?
torbenm@[EMAIL PROTECTED]  2008-03-04 10:19:06 
Re: reinventing ASCII?
Eliot Miranda <eliotm@  2008-03-04 13:18:31 
Re: reinventing ASCII?
"Charlie Gordon"  2008-03-05 03:58:24 
Re: reinventing ASCII?
ram@[EMAIL PROTECTED] (S  2008-03-05 03:26:51 
Re: reinventing ASCII?
torbenm@[EMAIL PROTECTED]  2008-03-05 10:31:40 
Re: reinventing ASCII?
Edward Feustel <efeust  2008-03-05 06:32:23 
Re: reinventing ASCII?
James Harris <james.ha  2008-03-05 15:05:37 
Re: reinventing ASCII?
torbenm@[EMAIL PROTECTED]  2008-03-06 11:34:33 
Re: NUL to terminate strings; was reinventing ASCII?
James Harris <james.ha  2008-03-08 07:16:34 
Re: NUL to terminate strings; was reinventing ASCII?
Eric Sosman <esosman@[  2008-03-08 10:48:58 
Re: NUL to terminate strings; was reinventing ASCII?
"Rod Pemberton"  2008-03-08 19:29:00 
Re: NUL to terminate strings; was reinventing ASCII?
Ulrich Eckhardt <dooms  2008-03-09 09:18:15 
Re: NUL to terminate strings; was reinventing ASCII?
torbenm@[EMAIL PROTECTED]  2008-03-11 11:04:42 
Re: NUL to terminate strings; was reinventing ASCII?
santosh <santosh.k83@[  2008-03-11 16:26:16 
Re: NUL to terminate strings; was reinventing ASCII?
richard@[EMAIL PROTECTED]  2008-03-11 11:10:37 
Re: NUL to terminate strings; was reinventing ASCII?
torbenm@[EMAIL PROTECTED]  2008-03-12 09:43:18 
Re: NUL to terminate strings; was reinventing ASCII?
santosh <santosh.k83@[  2008-03-12 14:25:04 
Re: NUL to terminate strings; was reinventing ASCII?
"Wilhelm B. Kloke&qu  2008-03-12 09:18:23 
Re: NUL to terminate strings; was reinventing ASCII?
Marco van de Voort <ma  2008-03-12 11:08:21 
Re: NUL to terminate strings; was reinventing ASCII?
"Wilhelm B. Kloke&qu  2008-03-12 12:33:14 
Re: NUL to terminate strings; was reinventing ASCII?
Marco van de Voort <ma  2008-03-12 14:11:25 
Re: NUL to terminate strings; was reinventing ASCII?
Chris Dollin <chris.do  2008-03-12 13:33:42 
Re: NUL to terminate strings; was reinventing ASCII?
"Wilhelm B. Kloke&qu  2008-03-12 15:34:40 
Re: NUL to terminate strings; was reinventing ASCII?
"Default User"   2008-03-12 18:22:45 
Re: NUL to terminate strings; was reinventing ASCII?
"Default User"   2008-03-12 18:22:45 
Re: NUL to terminate strings; was reinventing ASCII?
"Default User"   2008-03-11 21:26:05 
Re: NUL to terminate strings; was reinventing ASCII?
Micah Cowan <micah@[EM  2008-03-11 15:14:10 
Re: NUL to terminate strings; was reinventing ASCII?
richard@[EMAIL PROTECTED]  2008-03-11 22:27:14 
Re: NUL to terminate strings; was reinventing ASCII?
Morris Dovey <mrdovey@  2008-03-08 09:45:05 
Re: NUL to terminate strings; was reinventing ASCII?
Ben Bacarisse <ben.use  2008-03-08 17:22:36 
Re: NUL to terminate strings; was reinventing ASCII?
billg999@[EMAIL PROTECTED  2008-03-08 18:27:46 
Re: NUL to terminate strings; was reinventing ASCII?
James Harris <james.ha  2008-03-09 17:16:03 
Re: NUL to terminate strings; was reinventing ASCII?
richard@[EMAIL PROTECTED]  2008-03-10 01:08:23 
Re: NUL to terminate strings; was reinventing ASCII?
Ben Bacarisse <ben.use  2008-03-10 12:13:19 
Re: NUL to terminate strings; was reinventing ASCII?
James Harris <james.ha  2008-03-10 08:45:25 
Re: NUL to terminate strings; was reinventing ASCII?
"Rod Pemberton"  2008-03-10 19:26:16 
Re: NUL to terminate strings; was reinventing ASCII?
Eric Sosman <esosman@[  2008-03-10 21:03:06 
Re: NUL to terminate strings; was reinventing ASCII?
Marco van de Voort <ma  2008-03-11 11:06:14 
Re: NUL to terminate strings; was reinventing ASCII?
CBFalconer <cbfalconer  2008-03-11 15:22:58 
Re: NUL to terminate strings; was reinventing ASCII?
Eric Sosman <Eric.Sosm  2008-03-13 17:37:20 
Re: NUL to terminate strings; was reinventing ASCII?
rlb@[EMAIL PROTECTED] (R  2008-03-14 09:32:54 
Re: NUL to terminate strings; was reinventing ASCII?
Eric Sosman <esosman@[  2008-03-14 09:21:41 
Re: NUL to terminate strings; was reinventing ASCII?
"Rod Pemberton"  2008-03-14 17:48:27 
Re: NUL to terminate strings; was reinventing ASCII?
Morris Dovey <mrdovey@  2008-03-10 10:35:21 
Re: NUL to terminate strings; was reinventing ASCII?
"Rod Pemberton"  2008-03-10 19:09:27 
Re: NUL to terminate strings; was reinventing ASCII?
Eric Sosman <esosman@[  2008-03-10 21:00:14 
Re: NUL to terminate strings; was reinventing ASCII?
Marco van de Voort <ma  2008-03-11 11:04:46 
Re: NUL to terminate strings; was reinventing ASCII?
billg999@[EMAIL PROTECTED  2008-03-11 12:04:26 
Re: NUL to terminate strings; was reinventing ASCII?
billg999@[EMAIL PROTECTED  2008-03-11 12:07:36 
Re: NUL to terminate strings; was reinventing ASCII?
Neilist <lattoralee@[E  2008-03-11 14:28:23 
Re: NUL to terminate strings; was reinventing ASCII?
richard@[EMAIL PROTECTED]  2008-03-11 22:22:36 
Re: NUL to terminate strings; was reinventing ASCII?
Richard <devr_@[EMAIL   2008-03-11 23:23:21 
Re: NUL to terminate strings; was reinventing ASCII?
Jacko <jackokring@[EMA  2008-03-12 11:49:33 
Re: NUL to terminate strings; was reinventing ASCII?
Micah Cowan <micah@[EM  2008-03-12 19:01:00 
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 
Re: NUL to terminate strings; was reinventing ASCII?
BruceMcF <agila61@[EMA  2008-04-12 18:27:54 

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 Jul 25 18:03:22 CDT 2008.