4 ms·
No. 1. Optimizing compilers exist. 2. Addressing at fixed offsets is cheap (a single instruction): https://en.wikipedia.org/wiki/Addressing_mode https://en.wi
by nsajko 4y ago
No.
1. Optimizing compilers exist.
2. Addressing at fixed offsets is cheap (a single instruction): https://en.wikipedia.org/wiki/Addressing_mode https://en.wikipedia.org/wiki/Addressing_mode
0-based indexing is superior (as a default) because it simplifies a lot of common math, as discussed in TFA.
- mjevans 4y ago3. Less buggy for small systems since the Base Pointer address points directly to a record. 4. Macro expansion is often used to store indexes and other 'magic numbers' in Assembler, and this pattern originated either when Assembly was the primary programming language, or even earlier when humans directly punched out cards with machine instructions. Compilers in any remote sense of the luxury we have today did not exist or were not common.
- espadrine 4y agoThat is true for vectors, but not matrices, right? char at(char matrix[10][10], char i, char j) { return matrix[i][j]; } still has more computation on 1-indexed than on 0-indexed, I believe.
- contravariant 4y agoWell you've either got: memory_address + array_width*i + j or memory_address + array_width*(i-1) + (j-1) = (memory_address-array_width-1)+ array_width*i + j so you can just absorb the extra computation into the pointer.
- auggierose 4y agoTFA = Thanks For Asking?
- goatlover 4y ago> 0-based indexing is superior (as a default) because it simplifies a lot of common math, as discussed in TFA. If that was true, Fortran, Julia, R and Matlab would use 0 instead of 1-based.