4 ms·
I quite disagree, I think it makes two insightful points: 1. In this discussion, people often overlook that these numbers are applied to two different concepts
by cbolton 6y ago
I quite disagree, I think it makes two insightful points:
1. In this discussion, people often overlook that these numbers are applied to two different concepts: offsets and numbering.
2. If C had been designed with 0-based pointers (for offset calculation) and 1-based indices (for numbering the array elements) people would probably find this a strength, to have the most appropriate base for each case. It's an interesting what-if idea that I hadn't seen before.
- marcosdumay 6y agoIf C had 0-based pointers and 1-based indices, every CPU in existence would have a "subtract 1, multiply, and add" instead of an "multiply and add" instruction and everybody would think this is stupid because "multiply and add" could be used for a lot of things, but "subtract 1, multiply, and add" has only one use.
- cbolton 6y agoCPU instructions like load and move can apply an offset that is encoded as part of the instruction. This is more flexible than a special instruction for "offset=1", and useful beyond 1-based indexing. See for example https://www.cs.virginia.edu/~evans/cs216/guides/x86.html https://www.cs.virginia.edu/~evans/cs216/guides/x86.html and https://www.keil.com/support/man/docs/armasm/armasm_dom1361289873425.htm https://www.keil.com/support/man/docs/armasm/armasm_dom13612... . I'm not sure about "multiply and add"... Aren't these instructions for computing with floating point numbers rather than offsets?
- city41 6y agoCouldn't one based indexing be sugar the compiler provides? I don't think having pointers and indices behave differently is a good idea for the record.