1
I started studying C recently, and when trying to "dynamically" set the size of a Vector through a variable I get the following error:
error: ISO C90 forbids variable length array 'vector' [-Wvla]
Follows the code:
#include <stdio.h>
int main () {
int tam=0;
scanf("%d",&tam);
int vetor[tam];
return 0;
}
I have been researching and it is possible to change the version of C used by the compiler, I just do not know how.
This Feature has only been incorporated into C99. Download https://sourceforge.net/projects/mingw/ or yourself
gcc
by https://www.gnu.org/software/gcc/– anonimo
This is not something important. You’d probably be better off allocating
tam
bytes viamalloc()
or using a fixed value that it considers sufficient. In general programs for beginners who read the vector size via user will also read the values via keyboard, and no one will actually type more than a half dozen values... VLA may be important in some context, but when it’s important to you for sure you won’t be a beginner anymore and you’ll know what to do– arfneto
The function of inserting the vector size directly was implemented in C99, I was able to force mingw to compile in this version using the "-Std=C99" command by CMD. Edit: I was needing to solve an issue that specifically needed the user to insert the vector size, although I’m starting in the language, I didn’t have much choice. But thank you very much. :)
– André Marks