G
Guray Acar
Hi,
please consider the code:
int myFunction(void)
{ int x=0;
return x;
}
Now, my friend claimed that the code above is erroneous
because the int variable x is created in the stack. The function
returns the address of x in the stack. But the addresses in the
stack may change outside the function myFunction.
I found his argument quite plausible. However, I have seen
so many functions like the one above. I have written functions
doing what myFunction does, and they worked without error
for long time.
Can anyone clarify this issue ? TIA..
Regards
Guray Acar
please consider the code:
int myFunction(void)
{ int x=0;
return x;
}
Now, my friend claimed that the code above is erroneous
because the int variable x is created in the stack. The function
returns the address of x in the stack. But the addresses in the
stack may change outside the function myFunction.
I found his argument quite plausible. However, I have seen
so many functions like the one above. I have written functions
doing what myFunction does, and they worked without error
for long time.
Can anyone clarify this issue ? TIA..
Regards
Guray Acar