If I have a function like this:
void bla(int size) {
while(b){
char tmp[size];
......
}
}
tmp gets freed at each iteration of the while loop, right?
If I write this function:
void bla(int size) {
while(b){
char* tmp = alloca(size);
......
}
}
tmp gets freed at end of scope or at end of function?
alloca
. In fact this is the main difference between VLAs andalloca
- the scope of the automatic array is block scope with VLA and function scope withalloca
. – Mechanize