I’m using objective c and trying to output a value from a function. Apparently I am doing something wrong because I’m receiving an incorrect value.
This is my code:
-(float) getAngleBetween {
float num = 0.0;
return num;
}
and I’m calling it as follows:
float *theAngleBetween = [self getAngleBetween];
NSLog(@"Angle.. = %f", theAngleBetween);
Any help please?
There should be no
*.Since you are returning a
float, the receiver should have typefloatas well.float*means a pointer to float, which is entirely different fromfloat.BTW, make sure you declare
-(float)getAngleBetween;before you call[self getAngleBetween]. Put it in the@interface. If it is not declared before, the method will be assumed to have the type-(id)getAngleBetween;. On x86 returning aidand afloatuse different API (objc_msgSendvsobjc_msgSend_fpret), which may be the cause of wrong result.