4 ms·
A built in slice type (i.e. a (pointer, length) tuple) would prevent many of the issues with C strings without departing so far from the language design. If do
by CodesInChaos 8y ago
A built in slice type (i.e. a (pointer, length) tuple) would prevent many of the issues with C strings without departing so far from the language design.
If done from the beginning, slices could have gotten the `T[]` syntax and array-pointer decay could have been replaced by the easier to use and safer array-slice decay. But of course backwards compatibility prevents this now.
- wahern 8y agoBackwards compatibility doesn't prevent adding a slice type with specialized syntax. The stumbling block is 1) defining sane semantics agreeable to a majority of people and 2) implementing it in a major implementation. I hold out hope it'll happen, but I'm probably in denial. The fact that VLA function parameters were made optional in C11 doesn't bode well, but perhaps that's because it's incomplete--syntax and semantics stops short of what's needed to spur adoption of safer APIs. With a proper slice construct that was easy to use and integrate into idiomatic C code then there'd be more demand for implementing and using the necessary VLA compiler machinery, if not VLAs themselves.