Re: Pass by Reference
- Posted by jacques_desch Sep 12, 2009
- 2232 views
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.
But don't we know at any time that a reference is pointing to stack? If so we can forbid storage or return of that reference without flow analysis?