News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by vbezhenar on Wednesday August 24, 2022 @03:57PM (#32584921)
Waste 0th element or reuse it for something like length (hello, pascal strings). Another option is using base_address - element_size as your array value. Another option is using +element_size for all array accesses, assembly languages usually have this instruction. There’re many options to use 1-based indexing without sacrificing performance.
Re:Why do arrays start at 0? by xg15 on Wednesday August 24, 2022 @04:24PM (#32585270)
> assembly languages usually have this instruction

Is that so? I wasn't aware of that.

Re:Why do arrays start at 0? by vbezhenar on Wednesday August 24, 2022 @06:15PM (#32586515)
At least x86_64 can put something like `ptr[index * 4 + 4]` in one instruction (assuming that variable values are in registers). Not completely sure about ARM.
Re:Why do arrays start at 0? by chinabot on Wednesday August 24, 2022 @10:31PM (#32588714)
newer pascal strings are #0 terminated, original pascal strings were 255 chars max with string[0] being the string length, they were also not Unicode friendly, newer pascal compilers still support this as the shortstring type. I use pascal style strings in my embedded C library I wrote in 1989 much more efficient on 8/16-bit systems