Reputation: 349
I would like to pass a pointer as an argument into a function that normalizes the vector pointer that was passed as an argument.
Here are the functions:
float norm(Vector *v) {
float len;
len = sqrt(pow(v->x, 2.0) + pow(v->y, 2.0) + pow(v->z, 2.0));
return len;
}
Vector normalize(Vector *vec){
Vector normVec;
//calls norm function which also takes a pointer of vector type as argument
float norm = norm(&vec);
normVec.x = vec->x/norm;
normVec.y = vec->y/norm;
normVec.z = vec->z/norm;
return normVec;
}
I get this error:
error: called object ‘norm’ is not a function or function pointer.
How can I get this function running smoothly?
Upvotes: 2
Views: 41
Reputation: 20229
That is because your float norm
variable shadows the norm()
function.
Name one of them something else.
Also, vec
is already a pointer, no need to take its address (&vec
) when you pass it to norm()
Upvotes: 3