4 ms·
"Checked C introduces three varieties of checked pointer: • ptr<T > types a pointer that is either null or points to a single object of type T. • array_ptr<T
by Animats 5y ago
"Checked C introduces three varieties of checked pointer:
• 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 http://www.animats.com/papers/languages/safearraysforc43.pdf
- opnitro 5y agoSlightly more to that, since it provides a mechanism for integrating it with existing C programs (so called, Interface Types or I-Types for short).
- pjmlp 5y agoOne actually did, the one used by Apple on iBoot. But that isn't what you mean, I know.
- xenadu02 5y ago> The trouble is, you've created another C variant, one with checking. There are many of those, and none have caught on. 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.
- adgjlsfhk1 5y agoWhy is the answer to get more people on a committee and not to realize that the era of languages being designed by committee is over?
- rkagerer 5y agoAt the risk of asking a really stupid question, is this basically "generics" for C?
- pjmlp 5y agoSince C11, C already has a kind of pseudo-generics.