3 ms·
> It would not be difficult for the compiler to only allow arrays of that length to be passed as parameters It would be extremely difficult for the compiler, w
by geocar 11y ago
> It would not be difficult for the compiler to only allow arrays of that length to be passed as parameters
It would be extremely difficult for the compiler, without changes to the C spec and most ABIs, to simultaneously provide that protection for heap-allocated objects, for example:
foo(malloc(30));
> Developers who handle arrays of arbitrary length tend to already encode a length parameter, it's this case where it looks to the developer like they are encoding a length value that is the deceptive/problematic case.
The most common arrays of arbitrary length in C programs are almost certainly C "strings" which are usually 0-terminated instead of including a length value.