News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by Sirened on Thursday August 25, 2022 @03:09AM (#32590555)
not really? It just changes how the compiler emits the x := *(addr + idx) operation where instead of doing something like

    ldr x, [addr, idx]
it just does

    sub t1, idx, #1
    ldr x, [addr, t1]
If we're talking about C, accessing invalid/OOB indices is undefined and so if idx happens to be zero and unsigned, we'll overflow and hit something unexpected, which is fine.
Re:Why do arrays start at 0? by jbaczuk on Thursday August 25, 2022 @10:01AM (#32593838)
That's what I was thinking too, except that they have a point. You might end up using more bytes to store indexes as variables (if the index is 256 for example), than you would with zero indexing.