Re: Pass by Reference
- Posted by DerekParnell (admin) Sep 12, 2009
- 2269 views
jacques_desch said...
At parse time we know that a variable is on stack and so can forbid reference to it.
The problem is not so much that we make a reference to a stack variable, but that we allow that reference to be returned by the routine. For example, a routine could pass a reference to a local variable to another routine and that could be safe. So disallowing references to local vars or arguments is not what is required, but disallowing any such references to exist after the routine ends.
When passing references to stack vars to other routines, it is okay so long as those routines don't store the reference anywhere that will still exist after the original routine ends. This is difficult and requires flow analysis at run-time.