RE: 0-based Indexing

new topic     » goto parent     » topic index » view thread      » older message » newer message

> From: gertie at visionsix.com [mailto:gertie at visionsix.com]

> > On 16 Jul 2003, at 17:26, jbrown105 at speedymail.org wrote:

> > I have heard that the technical reason that sequences in 
> > Euphoria start at 1 is because in the C array that is used
> > internally, element 0 is used to hold the length of the
> > sequence. Not sure if this is true or not.

Not really.  A sequence is actually a structure.  It basically stores three
things:  the length of the sequence, a reference count and a pointer to the
data.  It actually used to point to the first element, so you had to convert
bases when working with a slice.  But now it pads the data with a
non-existent 0-th element.
 
> BASIC and Pascal used the first byte as length. (It feels odd 
> that RobC would use an example from Basic, and still not
> implement CASE and GOTO.) So the string storage data did
> actually start at zero offset, but not the string itself.
> Naturally my gripe with Turbo Pascal is that it began a move 
> to C strings, so one could not store a null in byte in the 
> string. But then, DOS frowned on that too.

Actually, the BSTR (basic string--as used by VB and COM and prolly others,
too) stores the length of the string in the four bytes preceding the data,
but the pointer to the string points to the data.  Also, the string is
unicode.

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu