3 ms·
As far as I know, nothing in the C/C++ standard precludes fat pointers with bounds checking. Trying to access outside the bounds of an array is merely undefined
by ummonk 5y ago
As far as I know, nothing in the C/C++ standard precludes fat pointers with bounds checking. Trying to access outside the bounds of an array is merely undefined behavior, so it would conform to the spec to simply throw an error in such situations.
- shakna 5y agoI believe that's how D's betterC compiler [0] works, whilst retaining the memory safe features. [0] https://dlang.org/spec/betterc.html https://dlang.org/spec/betterc.html
- gpderetta 5y agoThere's address-sanitizer, although for ABI compatibility the bound is stored in shadow memory, not alongside the pointer. It is very expensive though. A C implementation with fat pointer would probably have significantly lower overhead, but breaking compatibility is a non-starter. And you still need to deal with use-after-free.