This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

create variable length array

hello, i need to create variable length array. If i try to create this, i have infinite or empty array. I know that variable length array(vla) work after c99, but in documentation written that can be added --vla flag. I used c90 and --vla flag (option for target->c/c++>misc controls) and have error " --vla is underfinded". I tried use c99 standart where vla included, and i have empty (without length) array. If i use length variable from define or use int bytes[5] directly i have correct result. But i can not use define all time, because i need variable array. In eclipse it works, in keil with different standarts and versions of compiler i can't create variable length array.

#include "stdlib.h"
#define k 5
int main(void)
{
    int i;
	
	int ind=0;
	for (i=0;i<=5;i++){
	ind=i;
	}
    int bytes[ind]; //work if k or 5 or 0x05
return 0;
}

  • Yes, "--vla" is an Arm Compiler 5 option. And as you did not specify what compiler you use, it allows only guessing. Also, I do not understand the issue is? Where in your example code is something not working? "bytes" array there is also not used for anything. So a compiler might optimize this away.