Passing variables by reference
PhreaK
Posts: 966
Within netlinx is it possible to pass a variable by reference? If so, how?
0
Comments
From the help file:
The NetLinx compiler passes all variables by reference. This means that the variable the subroutine operates on is the same variable the caller passed. Any change made to a variable passed as a calling parameter updates the value of the variable from the perspective of the caller. You can take advantage of this pass by reference feature to return an updated value through a calling parameter rather than as the return value.
Constants, on the other hand, are passed by value. When this happens, a copy of the parameter is delivered to the subroutine. Any change made to the variable representing the constant is lost once the function or subroutine finishes.
Paul
Cheers for that.
You mean you haven't got a caffeine drip yet? How do programmers ever expect to get the job done without the right tools. Maybe start out with caffeine tablets to get into it and then move on to the harder options...
Why would you ever do this? I can't think of any reason why I would ever want to pass a string by value when it can be passed by reference. It just opens up a can of bugs.
Paul
Sometimes it's easier to bust a string up while parsing it, but you don't want to mess up the original in the process. I generally don't bother with any attempts to pass the value in those cases though, I just make a local copy and work on that instead.