News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by steveklabnik on Friday August 26, 2022 @07:50AM (#32606125)
C++ requires every value to take at least one byte of memory, but this isn’t true of all languages. Additionally, C++20 adds [[no_unique_address]], which allows zero-sizes types.

iopq points out Rust as a language that does allow zero length arrays in a sibling comment.

While ISO C does not allow zero length arrays, GNU C does. There’s also flexible array members, which can be length 0.

Re:Why do arrays start at 0? by foobarbaz33 on Friday August 26, 2022 @08:39AM (#32606623)
I'd say this transcends language.

Sure a language can define some abstraction that says "hey I'm length-0 array!". But this is more like a statement of "hey I don't exist yet, but if i do exist in the future I'll be of type array and at least length-1".

You can't access index 0 of a length-0 array.

You can only access index 0 of length-1+ array.