See a problem with this procedure?

Started by
2 comments, last by paulcoz 24 years, 1 month ago
Can anyone see what's wrong with this procedure / procedure call: (define global "vertex" structure here) int numpts; vertex scrvtx[20]; ClipScreen(numpts,scrvtx,numpts,scrvtx); // procedure call // procedure void ClipScreen (int numin, vertex *vtxin, int numout, vertex *vtxout) ( (body of procedure code here - calculate new values in local variables) numout = (new value here) vtxout = (new value here) ) // end ClipScreen I want to send the values of numpts and scrvtx (in the main program) into the procedure, then have some new values calculated which are then returned to the main program and put back in numpts and scrvtx again. The pointers * are for the arrays. Basically, I had the ClipScreen code working fine in my main program but now I have put it in a procedure it won't go. I am guessing I must be passing the values between the main program and procedure (or vice versa) incorrectly. Thanks, Paulcoz. Please ignore the brackets, curly ones don't show up remember? Edited by - paulcoz on 2/22/00 8:18:16 PM
Advertisement
if you just want to return the numpts and scrvtx back after you are done with them you do not need to declare different parameters for them (unless it is for some special reason). You could just use a reference or a pointer for the int and leave scrvtx as a pointer and they will reflect the changes that you made to them inside the function.
---Ranok---
A clarification: just setting the value within the procedure of vtxout will not cause a change to the scrvtx values as it stands. However, altering the vertex buffer pointed to by vtxout will cause a change to scrvtx values.

In other words

vtxout = new vertex[20];

wouldn''t have any effect, but

vtxout[0].x = 0;

would have an effect.

However even if you passed a reference to scrvtx rather than a copy on the stack, that is to say (vertex *)& vtxout,
vtxout = (some new value) would likely cause a fault because the scrvtx values are pushed on the stack.
Thankyou Ranok & SiCrane.

This problem is solved. I changed the procedure so that it only accepts two parameters (numpts and scrvtx) making it read:

ClipScreen(int *numpts, vertex *scrvtx)

Then I altered the original values passed into the function by referring to *numpts and vertex[cnt] (cnt being the counter in a loop).

Paulcoz.

Edited by - paulcoz on 2/23/00 9:17:49 PM

This topic is closed to new replies.

Advertisement