very strange passing of arguments
Hi everyone,
something very strange is happening in a very simple code;
specifically, I have this function:
Code:
void flinspace(float vmin, float vmax, int n, float *VECT)
{
//!!! VECT must be allocated starting from 1 for this function to work properely
int i;
float dv;
// WARNING NOTE THIS PRINTING LINE!!!
//printf("vmin = %f vmax =%f\n", vmin, vmax);
VECT[1] = vmin;
for (i=2; i<=n; i++){
dv = (vmax - vmin)/(n-1);
VECT[i] = VECT[i-1] + dv;
}
return;
}
now, this function is called by a main function that passes the correct arguments to it as expected. However, here is the very strange behavior:
although argument 1 and 2 (float vmin, float vmax) are not supposed to be modified within this function, once I comment the "printf" line above (see WARNING NOTE above), vmin and vmax ARE in fact modified randomly within this function, and are returned to the calling function with a different value from what they were assigned;
on the other hand, when I UNcomment the print line, everythign stands still, and the only variable that is returned with a new value is the expected/wanted VECT.
Is anyone able to help me understand how this is possible?
I am on a Mac OSX 10.5 with GCC 4.0.1
Thank you in advance