3 ms·
> I don't get why zero-indexing requires so much justification. Here are two powerful reasons [...] Reasons which I feel are too C-like and high level already.
by lloeki 13y ago
> I don't get why zero-indexing requires so much justification. Here are two powerful reasons [...]
Reasons which I feel are too C-like and high level already. The article falls into the same trap and says this as a counter argument:
> It’s not about * i = a + n * sizeof(x) because pointers and structs didn’t exist.
But I actually read this as an argument in favor of zero-based index origin: since pointers and structs did not exist, any form of memory addressing and data storing/retrieving had to be done at some lower level, and if you did it by hand, you will for sure align the start of your in memory handmade array-like structure at the address of it, then merely add to the register holding the address an offset maybe itself stored in a register, and certainly you would not add 1 again to those, because the idea would not even cross your mind to lose one and one byte/word of memory and one cycle, as it would just make no sense at that level.
Subsequently, C (or B or A or whatever) evolves the process and embeds into the language such arithmetics, abstracting it under monikers such as "pointer", "struct" and "array" and adding utility functions like "sizeof", so that you don't have to remember if this or that CPU/asm uses ADD or ADL, or is foo-aligned, or uses bar calling convention.