I am writing code for the iPad. I have a point structure that I define:
typedef struct __Point32_t
{
int32_t x;
int32_t y;
}Point32_t;
Here is my code to receive a structure back from an objective-C method:
Point32_t ModalityPan = [self ReadPoint];
Here is the method:
-(Point32_t)ReadPoint
{
Point32_t P;
P.x = [self ReadInt];
P.y = [self ReadInt];
return P;
}
The assignment of the return value to the structure creates an error at compile time. The error claims I have an invalid initializer. If I change the assignment to:
Point32_t * ModalityPan = [self ReadPoint];
the error goes away. So I am left wondering what is actually being passed back in Objective-C. I have searched through many posts, some here at SO, and I am under the impression that structures are passed and returned to and from methods in Obj-C without needing to reference the structure (e.g., I am allowed to pass by value).
Can anyone explain what is happening under the hood here? What is coming back, a reference or a structure? and if a structure, why do i need to specify a reference as the type of variable being assigned to?
Well it turns out that the compiler was warning me in a very indirect way that my method was not defined in the @interface and the implementation for the method was below my using it. So the compiler appears to not have been able to figure out what the return type was. It compiles correctly now.