Quote:
Originally Posted by Sane
- When you are declaring an array, if you need to make the size dynamic (dynamic size is when the program does not yet know the size until after it has been compiled), then you need to use some other techniques such as "malloc" or "new".
|
Don't mean to be pedantic, but thats not 100% true. The C99 standard allows variable length arrays. That is, an array of automatic storage duration whose length is determined at run time.
For example the following code is valid:
int foo(int len)
{
int vla[len];
for (int i = 0; i < vla[len]; i++)
vla[i] = i;
for (int i = 0; i < vla[len]; i++)
printf("%i\n", vla[i] = i);
}
Of course VLA operands will cause problems when compiled with C++. As you mentioned you could use C or C++, you may want to consider moving to a compiler that will support C99.
of course you must also make sure that the expression you are using to specify the size of the array is defined first

.