E. Robert Tisdale said:
Keith said:
E. Robert Tisdale writes: [...]
It seems to work just fine for me.
Of course it does. You're using a C99 compiler
(actually an incomplete one) that supports VLAs.
The OP is presumably using a compiler that doesn't support VLAs,
probably a C90 compiler.
I don't know that and neither do you.
That's why I wrote "presumably" rather than "certainly".
[...]
I don't know what Candy's problem is.
It didn't show us any diagnostic messages
or even tell us which compiler it was using.
Yes, more information would have been useful, but the assumption that
the OP is using a compiler that doesn't support C99 VLAs is the only
reasonable explanation, and one that should have immediately occurred
to any knowledgeable C programmer.
[...]
So what?
Must C programmers be forever constrained by obsolete compilers?
I hope not, but I'm willing to accept the reality that those
constraints have not yet been entirely eliminated.
There are plenty of C99 compiler that will accept Candy's program.
And there are plenty of C90 compilers that won't. Since Candy asked
why the code wasn't compiling, and since there's a single likely
explanation, saying that it works for you is unhelpful.
Even assuming a C99 implementation, you might at least have pointed
out that, given
const int n = 5;
int buf[n];
buf is a VLA, not an ordinary array as one might expect, because n is
not a constant expression.