On 08/09/2009, at 1:31 AM, Paulo F. Andrade wrote:

I don't get this. Won't the call

[sender value]

be dealt by objc_msgSend? Will it not traverse the isa pointer to get the method table and find the method named "value" and call that? At least from the UISlider class hierarchy there seems to be only one method named "value", no ambiguity there.


Yes, but the return type will cause different compilation of objc_msgSend. There are several variants of that (obc_msgSend_fpret, objc_msgSend_stret, etc) depending on which registers are expected to return what sorts of values - structs vs. floats vs. integers/objects for example. So the right method will get called but within the wrong context of what will be returned. You can verify this yourself by disassembling some variants of calling a test method - if only the return type varies and the compiler can't disambiguate based on class of the receiver, it will compile the first version it finds.

What's probably occurring in your case is that the compiler has used a version (such as -(id) value) that returns its value in a certain register, whereas the -(float) value method returns it in a different register (an fp register, generally). It just so happens that the register that the caller pulls the result from holds the slider object.

I know this. I just want to fully understand why this is happening for this particular name "value" and not for "maximumValue".

Probably because -value is ambiguous and -maximumValue is not.

Trust me - this happens. It's bitten me once or twice and I won't let that happen again, as it's so hard to understand what's going on and debug it.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to