Re: 0-based Indexing

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

On Wed, 16 Jul 2003 16:36:18 -0500, "C. K. Lester"
<cklester at yahoo.com> wrote:

>
>
>Derek splained (snippage occurred):
>
>> > I don't get it. Why do some languages use 0-based indexing? It's got=
 to
>be
>> > the dumbest thing in programming language history. Or maybe not.
>> >
>> The index is actually an offset from an address.
>
>Okay, I get that... and that's reasonable for the behind-the-scenes data
>manipulation, but why not hide that detail and use 1-based indexing? Is =
it
>that much of a performance issue? Like Greg said, 1-based indexing is =
more
>intuitive, easier to read and understand...
>
I'm with you on this one, apart from: What performance issue?

If an array starts at say #6A8, and each element is say 4 bytes,
then 0-style you find the i'th element by calculating #6A8+(i*4).
On 1-style you find the i'th element naively by #6A8+((i-1)*4),

...OR - Just pre-calculate the base address and do #6A4+(i*4)...

oh, look, no overhead whatsoever!

I believe, way back when, someone guffed big time thinking this would
help. They were wrong, in my opinion.

It possibly makes sense if the array starts near #0, but C (and
assembly) gleefully ignore carry and overflow bits, so I don't see the
problem with that either.

Euphoria Rocks!
Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu