[TUHS] Array index history
krewat at kilonet.net
Thu Jun 8 04:46:29 AEST 2017
If you think of an array as a memory area of bytes, words, whatever, the
simple way to deal with it is the index being 0 is the first in the array.
Why go to the trouble of decrementing the index to retreive the first
ALGOL did indeed have arrays with bounds:
INTEGER ARRAY K,L[0:10,0:10];
Two arrays, K and L with 0 first, 10 last. Total of 11 elements.
Of course, it's a "higher level" language than C. My thinking on the
subject is that C is very close to assembler, so if you're using for
example Intel X86 instructions:
MOV AL,[SI + ARRAY1] ; retrieve the SECOND
Likewise, for words, just left-shift SI one bit.
For me having started out in assembler (actually, MACRO-10 on a PDP-10),
it's intuitive as to why/how C does arrays.
More information about the TUHS