What’s up with zero-based arrays?
From the series "What the heck were they thinking": Every now and then I find myself wondering about some things that just don’t make sense on the software development world. I’ll start blogging about that type of thing just so that I can keep track of those things. One thing that is just…
3 responses to “What’s up with zero-based arrays?”
-
Actually, zero-based arrays are perfectly natural from the machine\’s point of view. An array is simply a contiguous sequence of bytes in memory. The memory address of any given element of an array can be calculated from its element number, the starting address of the array, and the length of each entry. The offset from the starting address of the array to the start of the nth element is ( length * ( n – 1)). The first element of an array therefore has an offset of zero, which is why zero-based arrays are natural. It actually takes some manipulation behind the scenes to implement the more intuitive one-based array in a programming language.
-
Hi Rick,I was pretty sure somebody would come by with an explanation for that non-sense. You academic people. :)If we were to see things from the perspective of what\’s natural for the machine, then we should drop everything and just type 1s and 0s, right? No need for fancy programming languages or IDEs. 😉
-
[…] still look at zero-based arrays and think “what the heck?”. […]




Leave a Reply to 15 Year Anniversary! | Claudio Lassala's BlogCancel reply