K
Kelsey Bjarnason
[snips]
fixing that somewhat:
void fn(void)
{
int a = 6;
}
int main(void)
{
int a = 78;
fn();
return 0;
}
Not as written. Before the call to fn, _a variable's_ value is 78.
During the call to fn, _another variable's_ value is 6. A hypothetical
compiler could do the job thusly (intermediate code stage):
..fn
fn_a = 6
jump reg_r
..main
main_a = 78
reg_r = @end
jump @fn
..end
...
The compiler creates two entirely different variables - fn_a and main_a -
then stores a "return address" in a register and does an absolute jump to
fn, followed by an absolute jump to the address in reg_r - the return.
Different contexts, different variables, different functions, call and
return - and not a stack needed anywhere.
Not sure what the example was supposed to prove, but if it was anything
relevant to the requirement of a LIFO structure, it failed.
Yes it does
int fn(void)
{
int a = 6;
}
int main(void)
{
a = 78;
fn();
}
fixing that somewhat:
void fn(void)
{
int a = 6;
}
int main(void)
{
int a = 78;
fn();
return 0;
}
Before the call to fn() the value of "a" is 78.
During the call to fn it is 6.
Not as written. Before the call to fn, _a variable's_ value is 78.
During the call to fn, _another variable's_ value is 6. A hypothetical
compiler could do the job thusly (intermediate code stage):
..fn
fn_a = 6
jump reg_r
..main
main_a = 78
reg_r = @end
jump @fn
..end
...
The compiler creates two entirely different variables - fn_a and main_a -
then stores a "return address" in a register and does an absolute jump to
fn, followed by an absolute jump to the address in reg_r - the return.
Different contexts, different variables, different functions, call and
return - and not a stack needed anywhere.
Not sure what the example was supposed to prove, but if it was anything
relevant to the requirement of a LIFO structure, it failed.