Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Influence of order of parameters in procedure 1

Status
Not open for further replies.

Hermanator

Technical User
Jan 16, 2002
30
0
0
NL
I hope that somebody is able to solve this little mystery:

I am working on a numerical simulation program. It calculates a certain device current and puts this in an output file. To keep track of the changes I make to the program, I compared the output files of different versions. After making some small changes that should not influence the calculation algorithm, I observed a small change in the output values. After a long search, I have managed to track it back to the following:

In the program a procedure was declared:
Code:
PROCEDURE Calculate(VAR x: vector; y, z: vector);
Where "vector" is a declared type of an ARRAY of DOUBLE. Obviously, since all parameters of the procedure are vectors, I changed that line by:
Code:
PROCEDURE Calculate(VAR x, y, z: vector);
This change causes a small change in the output values, while it should not at all influence the calulation algorithm.

Do the 2 different options signify something different?
 
The only influence on results for "var" is that it enables the direct passing of a variable, which may be changed. For the first procedure definition, X is saved/changed out of the procedure, while Y and Z are not. In the second one, all three are saved/changed.

To simplify things, it really doesn't matter for input, but output of a procedure requires "var". But the best practice is to not pass var for input variables and pass it for output. The first procedure type tells me that X is an output variable, and Y and Z are input variables.

But overall, whether a result is true or not should not be influenced by defining procedure variables one way or the other.

Dilbert is not a fictional cartoon. It is a documentary.
 
Of course, that's it. I failed to realize the significance of "VAR".
It turns out that both y & z get changed inside the procedure, but that this change shouldn't be passed to the main loop.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top