Re:Tell HN: C Experts Panel – Ask us anything about C
by knz42 on Tuesday April 14, 2020 @09:43AM
(#22865825)
What is the story behind the removal of VLAs from C99 in later revisions?
[ Parent
| on HN ]
Re:Tell HN: C Experts Panel – Ask us anything about C
by AaronBallman on Tuesday April 14, 2020 @10:13AM
(#22866214)
VLAs are still present in C17 and have not been removed. They are, however, an optional feature with a truly weird (IMHO) feature testing macro. If '__STDC_NO_VLA__' is defined to 1, then the implementation does not support VLAs.
IIRC, this macro was added to C11 along with a batch of other "these are optional" macros for atomics, complex, threads, etc. However, I don't recall whether C99 adopted the features as optional features and missed the feature testing macro, or if they were required features in C99 that we made optional in C11.
Re:Tell HN: C Experts Panel – Ask us anything about C
by stephencanon on Tuesday April 14, 2020 @10:49AM
(#22866681)
Complex and VLA were required by C99, but made optional in C11. The others were new in C11.
Re:Tell HN: C Experts Panel – Ask us anything about C
by rseacord on Tuesday April 14, 2020 @12:42PM
(#22868143)
So I spend a possibly unreasonable amount of time and page space discussing VLAs in the Effective C book. I understand there are some problems with them, but for what it is worth, I really like the feature, particularly when used in function prototype scope.
Re:Tell HN: C Experts Panel – Ask us anything about C
by jedbrown on Tuesday April 14, 2020 @05:44PM
(#22871862)
I usually don't let them leak into public interfaces, and don't allocate VLAs, but really like VLA pointers for multi-dimensional array processing such as []:
double (*a)[N][P] = (double (*)[N][P])a_flat;
for (i=0; i<M; i++)
for (j=0; j<N; j++)
for (k=0; k<P; k++)
a[i][j][k] = f(i, j, k);
The alternative would be a_flat[(i*M+j)*P+k] = f(i, j, k);
which is a lot more error-prone. I understand that some implementation (MSVC) declined to implement VLAs, but I really wish that at least VLA-pointers could have remained a mandatory part of C11 and later standards.[] Has there been any discussion of adding GCC's "typeof" to the standard?
Re:Tell HN: C Experts Panel – Ask us anything about C
by alerighi on Tuesday April 14, 2020 @11:27AM
(#22867147)
They did not remove them, but made them optional.
Is a controverial feature, that can produce bugs, and are banned in a lot of project (one famouse, the Linux kernel).
Re:Tell HN: C Experts Panel – Ask us anything about C
by wuxb on Tuesday April 14, 2020 @10:22AM
(#22866321)
I can't live without it.
Re:Tell HN: C Experts Panel – Ask us anything about C
by DougGwyn on Tuesday April 14, 2020 @10:09AM
(#22866154)
What removal? C11 section 6.7.6.2 specifies the semantics.
Re:Tell HN: C Experts Panel – Ask us anything about C
by cesarb on Tuesday April 14, 2020 @10:17AM
(#22866266)
What the parent comment probably meant is that support for VLA was required in C99, but is no longer required in C11, so while code written for C99 could use VLAs without any special consideration, code written for C11 cannot depend on VLAs since it might not be present in all compilers.