Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > ObjC Assignment Problem (mystery)

ObjC Assignment Problem (mystery)
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2003
Status: Offline
Reply With Quote
Feb 10, 2004, 10:07 AM
 
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.]
(Last edited by Wandering Mango; Feb 10, 2004 at 10:58 AM. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2