pass by reference vs copy-in, copy-out

From: Geoffrey.Coram <Geoffrey.Coram_at_.....>
Date: Tue Mar 21 2006 - 14:54:31 PST
Sri's agenda for today had:
- Request for SV's pass-by-reference to be incorporated in AMS

I initially thought this was not an issue, but then David Miller
(I believe) pointed out that it could be for functions where the
same variable is passed for multiple arguments.  (Otherwise,
since analog_functions execute in zero time, there's no chance
for a variable to be altered by something else while the
function is evaluating.)

So, a problem example is as follows:

analog function myfunc(a,b);
  inout a,b;
  real a,b;
  begin
    b = 3;
    a = 2;
    myfunc = 2*b + 5;
  end
endfunction

and in the module:

  y = 4;
  x = myfunc(y,y);

If the arguments are pass-by-reference, then the "address"
of y is passed for arguments a and b, so that "a = 2;" also
affects the value of b inside the function, and the result
is that y=2 and x=9 in the module.

If the arguments are copy-in, copy-out, then x will get
the value 11.  What happens to y?


-Geoffrey
Received on Tue Mar 21 14:54:35 2006

This archive was generated by hypermail 2.1.8 : Tue Mar 21 2006 - 14:54:38 PST