3 ms·
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
by steveklabnik 4y ago
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.
- foobarbaz33 4y agoI'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.