4 ms·
But why? Why is this VLA parameter defined this way? It seems totally bizarre and unnecessary, but I suppose it must have been added to the standard to solve
by beeforpork 4y ago
But why? Why is this VLA parameter defined this way? It seems totally bizarre and unnecessary, but I suppose it must have been added to the standard to solve some kind of problem? Is the proposal for this feature available and gives some insight?
- mananaysiempre 4y agoYou can try trawling through the document log[1], but a big part of the C99 deliberations is either inaccessible or (like the drafts) explicitly kept secret from anyone but the committee. [1] https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log.htm https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_lo...
- ufo 4y agoI speculate it's for consistency with VLAs that are not function arguments, which is the more common use for VLAs. The original purpose of VLAs is to let you stack-allocate an array with a length that is not known at compile time. In ANSI C you must heap-allocate such arrays, using malloc.
- kllrnohj 4y agoseems like to avoid the introduction of constant expressions (constexpr) like is in C++. Which is why c++ doesn't have this issue, even though it can also take expressions as the expressions must be resolvable at compile-time.
- TazeTSchnitzel 4y agoAllowing arbitrary expressions allows self-documenting signatures: void concat_strs( int str1_len, const char str1[str1_len], int str2_len, const char str2[str2_len], char out_str[str1_len + str2_len], ); void manipulate_array( array_dim dim, int arr[dim.x][dim.y], ); Supporting things like printf() was probably not specifically desired, but it would be difficult to define it in such a way that it accepts all reasonable expressions and doesn't accept any "unreasonable" ones.
- saagarjha 4y agoTip: if writing new functions that take things that are not strings, try to avoid C’s mistakes with strncpy and putting “str” in the name.
- TazeTSchnitzel 4y agoThose are strings! Null-terminated strings are not special.
- saagarjha 4y agoIt’s only a string of it comes from the null-terminated region of France. Otherwise, it’s just sparkling character arrays