I'm trying to return two values, u
and v
, which I pass as arguments to the function get_uv( float u, float v )
.
Because double and float are not compatible with integer types, we can't convert them to pointer, and the following code give us error: cannot convert to a pointer type.
void calc_uv( float *u, float *v )
{
u = (float *) 0.0f;
v = (float *) 1.0f;
}
void anyfunction()
{
float u, v;
calc_uv( &u, &v )
printf("u: %f , v: %f", u, v);
}
It works if I use:
void calc_uv( float *u, float *v )
{
*u = 0.0f;
*v = 1.0f;
}
But I don't understand why, as u and v were already pointers. Can you explain to me what's going on here?
What is the best way to modify and return two float from a function?
I saw I can use something like float *f = malloc(sizeof *f);
but my goal is not to obtain a pointer by hook or by crook, just change the input values in the most elegant or concise way.