3 ms·
Why yes, yes it does! I did know (but seem to have forgotten) that it's only the first level of array-ness that decays to a pointer. It's unfortunate that the
by kiwidrew 6y ago
Why yes, yes it does! I did know (but seem to have forgotten) that it's only the first level of array-ness that decays to a pointer.
It's unfortunate that the resulting VLA-enhanced function is no longer compatible with the original:
/* original function */
void foo(size_t len, const char *str);
/* compatible signature but str[] decays to sizeless pointer */
void foo(size_t len, const char str[len]);
/* allowed but signature is no longer compatible with original */
void foo_improved(size_t len, const char (*str)[len]);
/* (this is how the non-VLA caller would see the signature) */
void foo_improved(size_t len, const char **str);
So what your example does show is that existing compilers already support this concept (no need for fancy dependent types) but the C99 standard explicitly prohibits compilers from acting on the VLA information contained within the const char str[len] declaration.