How to define an array inside a function in C?
- by Arunav Dev
So in my source file I have the folowin function:
void update(state* old_state, state* measurement, uint32_t size)
{
state new_state[size];
//some function using measurement and old_state and returning the result in newstate
arm_fadd_32(measurement,old_state,newstate,size);
// rest of the code
}
Now the compiler throws an error saying that
error#28:expression must have a constant value.
I think it's due to the fact that even though inside the method the size local variable is not changing the compiler is expecting a constant while defining the size.
I have tried the following:
int const a = size;
and then tried to reinitialize it says constant value is not known.
I did some research in internet and it appears that there is no easier way without using malloc, which I don't want to since I am using the code for some embedded application.
Is there a way to avoid this problem without really using malloc? Thanks in advance guys!