My supervisor saw something in my C code similar to:
size = f(some parameters);
int array[size];
He said that it is preferable to allocate such arrays with malloc
. His description was something like:
Allocating it on the stack like that requires that your stack remains valid for the entire run-time of the program.
I had no clue what he meant, so this is just as close as I remember to his wording by the end of the meeting, without knowing the actual meaning. What did he mean? (alternatively, maybe someone can explain another reason not to declare arrays in such manner).