RE: pass by reference

new topic     » topic index » view thread      » older message » newer message

Irv Mullins wrote:
> er...no, that's pass-by-value. 
> If I call foo(integer x) as follows:
> 
> x = 3
> foo(x)
> ? x => 3
> 
> No matter what happens inside the mysterious foo, x is still what it was 
> 
> before calling the function.
> Even if foo sets x to 99, it's only 99 while inside the foo routine.
> So foo is working with a copy of x, not the real x.
> 
> Pass-by_reference passes the actual variable, not a copy, so that 

atom addr_of_x
addr_of_x = allocate(4) 

> foo(var integer x)
>  x = 99
> end 

procedure foo(atom addr_of_x)
  poke4(addr_of_x,99)
end procedure

> foo(x)
> ? x  => 99

foo(addr_of_x)
? peek4u(addr_of_x) => 99
> 

> The variable IS changed within the routine, and remains changed 
> afterward.

yes


Regards,

Bernie

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu