Re:C99 doesn't need function bodies, or 'VLAs are Turing com...
by SavageBeast on Thursday August 04, 2022 @01:03PM
(#32345484)
The fact the array element isn't in quotes bothers me to some degree - with or without its crazy but the fact that the compiler just accepts it as a language construct as opposed to a value makes me want to drink another beer. But again Im thinking dereferencing here - and as you said thats not the case.
[ Parent
| on HN ]
Re:C99 doesn't need function bodies, or 'VLAs are Turing com...
by nneonneo on Thursday August 04, 2022 @01:09PM
(#32345550)
It’s not an array element :) The printf statement is part of the length expression, i.e. it’s setting the length of the array to the result of the printf call. So it is indeed a “value”.
This isn’t much different from writing something like this in JS:
var a = [];
a[console.log("Hello"), 1] = 42;
except that this indexes the array as opposed to setting its length.
Re:C99 doesn't need function bodies, or 'VLAs are Turing com...
by SavageBeast on Thursday August 04, 2022 @01:46PM
(#32345978)
I spent the past 10 minutes figuring out what to search for (C is very rusty here) regarding C arrays and initialization. Now that you point it out, it seems obvious. It certainly wasn't obvious when I read it though. This is some really obtuse use of a language here - hilariously so really. The code in the array is executed as a function that determines the array size and I see that now - thanks. If someone on my team did this for any reason I'm not sure If Id shoot them or put them in charge of something more important. If no other thing - THIS is why code reviews exist. Still it's an impressive use of a compiler. Thanks for nit picking - this has been very entertaining!
Re:C99 doesn't need function bodies, or 'VLAs are Turing com...
by shawnz on Thursday August 04, 2022 @08:25PM
(#32350053)
The feature is called variable length arrays (VLAs)
See https://www.ibm.com/docs/en/i/7.4?topic=arrays-variable-leng...