• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
int and short int on intel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

int and short int on intel


  • Subject: int and short int on intel
  • From: Jonathan Fewtrell <email@hidden>
  • Date: Fri, 12 Jan 2007 10:12:28 +0800

I have two classes, JF1 and JF2, each of which has an ivar called 'scale' of type int, with normal getter and setter accessors.

As part of an array-sorting routine, I use - sortedArrayUsingFunction:, the function in question being as follows:

int JFSortByScale( id panel1 , id panel2, void *context )
{
	int scale1, scale2;

	scale1 = [panel1 scale];
	scale2 = [panel2 scale];
	if ( scale1 > scale2 ) return NSOrderedDescending;
	else if (scale1 < scale2 ) return NSOrderedAscending;
	else return NSOrderedSame;
}

panel1 and panel2 can be of class JF1 or JF2, hence I use id rather than specifying the class. Incidentally, neither JF1 nor JF2 is a subclass of the other.

The problem I am having is that, on intel machines, if scale exceeds a certain value (which I think is 32k), scale1 or scale2 is set to a different value. It appears that either FF FF or 00 01 gets substituted for the first two bytes. It seems to be something to do with 2 byte and 4 byte ints.

I get a compiler warning that there is more than one method called - scale (apart from the ones in JF1 and JF2). The other is in NSDecimalNumber and is a short int. I assume this is leading to the problem, but I don't see why. I have been ignoring the warning because my understanding of ObjC was that at runtime the message - scale would be sent to the JF1 or JF2 instance and the method would duly be found and used and the NSDecimalNumber method would be irrelevant. And on PPC that is true. Even on intel, stepping through with the debugger shows the correct method is called, and yet scale1 and scale2 somehow end up being wrong.

What have I misunderstood? I can obviously fix the problem by renaming the ivars, but why should I have to?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: int and short int on intel
      • From: Chris Suter <email@hidden>
    • Re: int and short int on intel
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: NSImageRep slower in 10.4 vs 10.3?
  • Next by Date: Re: int and short int on intel
  • Previous by thread: Re: NSImageRep slower in 10.4 vs 10.3?
  • Next by thread: Re: int and short int on intel
  • Index(es):
    • Date
    • Thread