4 ms·
I would say it is sensible. Given that an array index is an unsigned integer, what are you going to do with an index of zero? Perhaps I've been influenced by w
by zabzonk 1y ago
I would say it is sensible. Given that an array index is an unsigned integer, what are you going to do with an index of zero?
Perhaps I've been influenced by writing a lot of code in assembler, way back when, but zero-based has always seemed completely natural to me, to the extent that I find it very hard to understand algorithms expressed in non-zero based code.
- Joker_vD 1y agoAn array index can be signed with no problem. If you're worried about the address calculations, well, the address of an array doesn't have to be the address to its initial element, does it? It can be the address of the element with index 0 (even if an array does not have such an index at all): arr: array[-2..10] of integer; pointer(@arr) == pointer(@arr[0]) Or you can use descriptors (dope vectors), but that involves quite an overhead. The books on compilers from the 70s (e.g. Gries's "Compiler construction for digital computers") have rather extensive discussions on both approaches.
- zabzonk 1y agoYes, I'm familiar with Pascal indexes, but I don't find them very natural for the kind of programs I write. I want functions/classes to do any sort of translation. > The books on compilers from the 70s (e.g. Gries's "Compiler construction for digital computers") Yellow cover, I think? My then GF bought it for Xmas at about 1984 or so. Not the best book on the topic, IMHO.