4 ms·
I don't think bounds checking can be done at compile time. Otherwise Java, Rust, Go et al. wouldn't need to incur the runtime overhead of the extra bookkeeping
by desdiv 12y ago
I don't think bounds checking can be done at compile time.
Otherwise Java, Rust, Go et al. wouldn't need to incur the runtime overhead of the extra bookkeeping int per array.
- jonhohle 12y ago-fbounds-checking, I'm sure there is a runtime cost, but it's provided by the compiler.
- rst 12y agoNot applicable to C -- "Currently only supported by the Java and Fortran front ends." https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Code-Gen-Options.html#Code-Gen-Options https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Code-Gen-Option... There have been bounds-checked implementations of C, but the runtime cost is very large. The problem is that to do it, you need to check not only explicit array references, but pointer dereferences as well -- and in order to make that work, each pointer needs to carry around with it its associated bounds. That, in turn, means that your pointer representation has to be something more (or other) than just a plain machine address.
- kibwen 12y agoI'm not an expert, but you can do this in a language with dependent types such as Idris. But given the historical progress of the industry, it will probably be a long, long time before such an idea percolates down into an industrial language.