4 ms·
C99 introduced variable-length array parameters and variable-length array pointers together with variable-length arrays (VLA). These take another parameter or v
by Findecanor 5y ago
C99 introduced variable-length array parameters and variable-length array pointers together with variable-length arrays (VLA). These take another parameter or variable as a length-parameter.
These became optional in C11 together with VLAs (for some reason) but are supposed to again become mandatory in C23.
However (yet, for some reason) the pointers can (in the latest published draft, still) only be inside procedures: not in structs or in global variables.
I think it would not be impossible for a C compiler to detect and produce a warning if an index used with such an array-pointer is not checked against the array-pointer's length variable.
This would not make bounds-checks automatic, but the use of these types could make compilers point out when bounds are not checked or checked incorrectly.
- melissalobos 5y agoPeople don't really get the distinction you make here, which is a shame. Often any VLA's are outlawed which is tossing the baby out with the bathwater.
- uecker 5y agoCompilers can already do this: https://godbolt.org/z/jMMa8n48r https://godbolt.org/z/jMMa8n48r Yes, putting them into structs is a missing feature. It is not in the draft because no compiler can do it and their is no implementation experience. I am working on it.