3 ms·
> When variables are allocated on the stack, the space for them with all compilers I have ever used (or written) is allocated on the stack once by adjusting the
by jcelerier 6y ago
> When variables are allocated on the stack, the space for them with all compilers I have ever used (or written) is allocated on the stack once by adjusting the stack pointer - i.e. for all of the variables of the function.
it's not a given
int algo(int*, int n);
int computation(int i, int n) {
int alloc[n];
return algo(alloc, n);
}
on some compilers (Keil for instance afair), alloc will be heap-allocated (and freed when leaving the function) even if it's "automatic storage" (what most people call the stack).
- divingdragon 6y agoIsn't variable sized array non-standard in C++? Variable sized array is kind of a special thing anyway so I wouldn't be surprised if some compilers do something special with it. Yes, the term "automatic storage" is more accurate here.