by Animats · 4y ago · 0 comments
• ptr<T > types a pointer that is either null or points to a single object of type T.
• array_ptr<T > types a pointer that is either null or points to an array of T objects. The array width is defined by a bounds expression, discussed below.
• nt_array_ptr<T > is like array_ptr<T > except that the bounds expression defines the minimum array width— additional objects may be available past the upper bound, up to a null terminator."
It's not hard to do this if you retrofit checkable array types. I've proposed that myself.[1] The trouble is, you've created another C variant, one with checking. There are many of those, and none have caught on.
[1] http://www.animats.com/papers/languages/safearraysforc43.pdf
Because none of these approaches have been adopted by the standards committee – of which most of the members think C as it is today is just fine and are not interested in these sorts of large-scale safety improvements.
If we as an industry could get some new blood on the committee this is an entirely solvable problem. It doesn't require a disruption either: the standard can specify that behavior is implementation defined when safety guarantees are violated so your embedded DSP target can continue whatever it is doing today but the rest of us stuck with 100s of millions of lines of C code can start making some improvements.
But that isn't what you mean, I know.