Given two functions, func1 and f2, with the following signatures:
void func1(){
int baba = 12345;
// printf the value of baba here
}
void f2(){
int loo;
//printf the value of loo here
}
...if I run my int main, which only has func1 then f2:
int main(){
func1();
f2();
}
...then the printed value of both baba and loo will be 12345. So my question is as follows:
Is this defined behaviour, or just something erroneous that my machine does?
If this isn't some erroneous thing my computer did, can you explain why the compiler chooses to store
loo
in the same address asbaba?
EDIT: I guess I should ask, if I have these EXACT two functions, will baba and loo have the same value on ANY machine?
I understand loo's value is the result of baba's leftover bits, and I understand that (on my machine, at least) the stacks of both are being laid out such that loo overlaps onto baba's old territory. Is it true that every machine would lay these two function stacks out in such a manner that baba and loo overlap? Using these two functions exactly as written, that is...