Re: unsigned long long + id = ???
Re: unsigned long long + id = ???
- Subject: Re: unsigned long long + id = ???
- From: Andrew Farmer <email@hidden>
- Date: Thu, 8 Feb 2007 13:31:58 -0800
On 08 Feb 07, at 12:57, Andrew Farmer wrote:
On 08 Feb 07, at 12:49, Claudio Procida wrote:
I have a class Foo with a method -(unsigned long long)size.
I realized today that when I get an id reference to an object of
class Foo, if I don't explicitly cast to (Foo *), the result is
meaningless.
I didn't check, but it *seems* to be interpreted as signed int
Here's the code:
- (id)outlineView:(NSOutlineView *)outlineView
objectValueForTableColumn:(NSTableColumn *)tableColumn
byItem:(id)item {
//...
NSLog(@"s:%qu", [item size]);
NSLog(@"s:%qu", [(Foo *)item size]);
And the results:
2007-02-08 21:19:40.093 Singular[19919] s:14065436521166900
2007-02-08 21:19:40.094 Singular[19919] s:6212
Why??
Because you're trying to print an integer as uint64_t. Format using
%u instead of %qu and you'll probably get more meaningful results.
Oops, I spoke a little too quickly there. Didn't realize your method
is supposed to return a 64-bit integer.
The critical bit, though, is that there are a lot of other objects
with a method -(int)size, which is what's assumed you mean if you
call [item size] without an explicit cast. The same method is being
called in both cases, but the compiler can't decide what return type
to use at runtime; it has to decide at compile time. And, unlike most
integer types, 32-bit and 64-bit integers are fundamentally
different: the details depend on your target ABI, but it'll suffice
to say that, unless you're compiling code for a 64-bit system (which
you can't do for AppKit yet), the generated code has to do some
different things to use a 64-bit return value than it would for a 32-
bit one.
_______________________________________________
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