On Apr 18, 2016, at 8:56 PM, Carl Hoefs <newsli...@autonomy.caltech.edu> wrote:
> 
> Suppose I have an object with a declared method signature:
>  -(void)myMethod:(BOOL)a_bool;
> 
> Q1: If I invoke it like this:
>  [self performSelector:@selector(myMethod:) withObject:nil];  // nil obj
> Will argument a_bool end up with a 0 value assigned to it?

Probably, but it's poor practice to rely on it.  The caller will store a 
pointer to either an argument-passing register or on the stack, depending on 
the platform.  The called method will interpret only 1 of those 8 or 4 bytes, 
but, since they're all zero, it will get zero no matter what.

> Q2: But if I invoke it like this:
>  [self performSelector:@selector(myMethod:) withObject:someObj];  // valid obj
> Will argument a_bool end up with a 1 value assigned to it?

No.  The called method will interpret 1 of the bytes as a bool and that byte 
may be zero or non-zero, depending on the exact value of the non-nil object 
pointer that was passed.  Since a valid object pointer may have a zero in, say, 
its least-significant byte, a_bool may be zero.

You should use another mechanism for invoking the method or create a separate 
method which takes an object pointer and calls -myMethod: appropriately by 
interpreting that object pointer, and invoke that using -performSelector:….

Regards,
Ken


_______________________________________________

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

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

Reply via email to