3 ms·
VLAs 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 ba
by jsmith45 4y ago
VLAs 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)); }