I would like to know if you could help me to know the idea behind pass by value and pass by reference that the compiler needs to make, what are the steps involved? I’d be really helpful if you could give me a hand on this since I’m working on a project which is a mini-compiler.
Share
It depends entirely on how the compiler handles variables (what could be termed the “environment”).
When variables are translated to memory references (such as in C compilers), pass-by-reference may be implemented by using pointers behind the scenes, with the compiler generating the necessary code to de-reference pointers. Pass-by-value is handled by copying data, then referring to the copy.
If the compiler uses a symbol table (which is more typical of interpreters than compilers) pass-by-value may be done by copying the existing symbol table entry to a new one for the new variable, while pass-by-reference would simply use the existing entry.
Other environments would require other approaches.