4 ms·
It might not be mind-boggling, but it is highly unusual to people who "think in C". This is not C! This kind of stuff is why purists stick to C89. I'm uneasy a
by jstanley 4y ago
It might not be mind-boggling, but it is highly unusual to people who "think in C". This is not C! This kind of stuff is why purists stick to C89.
I'm uneasy about variable-length arrays at the best of times. It hadn't even occurred to me that you might have a variable-length array as a function argument.
- jsmith45 4y agoVLAs in a prototype are sensible, because they decays to a pointer, and is thus functioning purely as documentation. In the function definition, it seems to basically also decay to a pointer, except that the compiler adds basically an assertion that the value in the brackets is greater than zero to the to the top of the function. That actually seems quite weird to me. I'd have been fine with the VLA acting like a proper local VLA with respect to things like sizeof, in which case the assertion makes sense. Or I'd have also been fine with it totally decaying to a pointer, making it just documentation. This half-way in between state is quite weird.
- unnah 4y agoNote that sizeof is useful on the inner dimensions of multi-dimensional array arguments: the following prints the value of m. int foo(int n, int m, double x[n][m]) { printf("sizeof(x[0])=%zd\n", sizeof(x[0])/sizeof(double)); }
- silon42 4y agoor RIIR is suddenly preferable.
- AlotOfReading 4y agoSerious question, but what "purists" remain on ANSI C? Even Linux has abandoned it as of 5.19. The only times I use it are when I'm writing something that requires ridiculous portability even to bizarre platforms and compilers. C99 is far more ergonomic in comparison, even if you have to avoid using some of the truly terrible design decisions that came along for the ride.
- alar44 4y agoEmbedded probably.
- AlotOfReading 4y agoThat's where I work. I haven't seen c89 in years outside those "extreme portability" projects like Linux and curl.
- arinlen 4y ago> Serious question, but what "purists" remain on ANSI C? It means nothing. It's a baseless attemt at an appeal to authority that has no merit.
- MayeulC 4y agoOh, but designated initializers are so useful!
- arinlen 4y ago> This is not C! This kind of stuff is why purists stick to C89. This personal assertion holds no water. People hold/held onto C89 because compilers like Visual Studio's C compiler failed to support anything beyond C89 for ages. https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-... It's my understanding that Microsoft adopted a role in the C standardization committee that was a kin to sabotaging any update beyond C89.
- pjmlp 4y agoMicrosoft saw no value in supporting C when C++ is a better option [0], they caved in because Microsoft Loves Linux (alongside key FOSS projects) implies loving C as well. Note that they aren't supporting the optional annexes and stuff like C atomics aren't supported. [0] - https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/ https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-an...
- Koshkin 4y ago> purists stick to C89 But the true Scotsman… uh, purist sticks to the K&R C as C89 has already lost some of the original elegance and simplicity. (Never mind that it’s a challenge since the general community has moved on.)