0

So, with this I make a VLA:

int main()
{
    const size_t LEN = 200; // as I know it's read-onlyy
    int array[LEN];
}

So I enstablished that VLAs are not more requested in C1.. In the C99 today they are optional... For this motivaiton, to use that code is not advised.

But if I do this:

#define MYLEN 100
int main()
{
    int xar[MYLEN];
}

or

int main()
{
    int xar[100];
    const size_t MYLEN = sizeof(xar) / sizeof(int);
}

I think I have:

  • In the first case I have a constant variable in the compile time, but it's more logic and not typed.
  • In the second case, a typed variable, (read-only)

But with it's more valid with the define directive as it's typical to C language.What do you suggest to use?

Anyway, the VLA can be used inside the main but it has not so sense.

1 Answers1

0

the posted code has no VLAs defined as the sizing is always known at compile time.

This would be an example of a VLA:

int myFunction( int size )
{
    int myArray[size];
}
user3629249
  • 16,402
  • 1
  • 16
  • 17
  • Why are not them a VLA? – Dr. Five Sep 27 '15 at 18:52
  • 1
    This answer is wrong. The first version in the question is well a VLA. As soon as the expression in the `[]` depends on an object, this is a VLA. This is how the C standard defines it. – Jens Gustedt Sep 27 '15 at 19:19
  • Just to clear up what @JensGustedt sir said, a `const` variable is not a compile time constant in `C`, it it called `const`-qualified. – Sourav Ghosh Sep 27 '15 at 19:45