I have a method with the following:
int newX, rect1X, rect2X;
Now, consider the following two lines of code (I):
newX = ([[self origin] x]) - ([[Rectangle2 origin] x]);
printf ("%i, %i, %i\n", [[self origin] x], [[Rectangle2 origin] x], newX);
And compare them with the following three lines of code (II):
rect1X = [[self origin] x];
rect2X = [[Rectangle2 origin] x];
newX = rect1X - rect2X;
printf ("%i, %i, %i\n", [[self origin] x], [[Rectangle2 origin] x], newX);
The problem is that the two pieces of code print out different results, and it is a mystery to me why this is happening. Now "[[self origin] x]" returns an integer in both I and II (assume it is 5); and "[[Rectangle2 origin] x]" also returns an integer in I and II (assume it is 2). But here are the results that are printed:
I: 5, 2, 0
II: 5, 2, 3
Why do I and II not yield the same results?
[Note: Problem solved. The header file was not specified, and so in I, the compiler did not know what sort of object was returned. When the assignment of newX was done in the form of several assignments, rect1X and rect2X cast the returns as ints. But in I, this was not done.]