-> > If Twiddle changes the value of its input parameter, the value of X in
-> > the calling routine will *not* be changed.
-> >
-> > But how easy is it to do the other way around? If the language is set
-> > up to call by value, can we write simple code that effectively calls
by
-> > reference? I can't think of an easy way to do it.
-> >
-> > Of course, the language may have specific commands to switch from one
-> > method of calling to the other, but without them, a dialect that
calls
-> > by value can't easily be made to call by reference.
-> Passing a pointer using VARPTR should work, shouldn't it?
Hmmm... Maybe. I'd have to think about that.
What I'm concerned about is the ability to pass numbers back from a SUB
to the calling routine. For example, in the program SUNALIGN, which I
posted here a couple of days ago, some three-dimensional trigonometry is
done by using two methods of representing a direction in space - e.g.
the direction of the sun in the sky, as seen by an observer on the
ground. One method is to state the azimuth (compass bearing) and angle
of elevation. The other is to state the X, Y, Z co-ordinates of the
endpoint of a unit vector pointing to the sun, with the observer at the
origin. A lot of 3D trig can be done very easily by switching to and
fro between these methods, with small operations on the arguments along
the way. To do this, the program has two SUBs, D2P and P2D. Each has
five arguments, X, Y, Z, AZ, and EL. D2P takes X, Y, and Z as inputs,
calculates AZ and EL and passes them back to the calling routine. P2D
does the conversion in the opposite direction. So, basically, each SUB
puts values into the variables in its parameter list that it uses as
outputs, and expects the calling routine to be able to receive them and
use them in later calculations.
Could this be done with VARPTR? Certainly, not as easily.
dow


|