• 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
Re: Multiple declarations of objc_msgSend_stret
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple declarations of objc_msgSend_stret


  • Subject: Re: Multiple declarations of objc_msgSend_stret
  • From: Greg Parker <email@hidden>
  • Date: Thu, 3 Feb 2011 18:38:23 -0800

On Feb 3, 2011, at 6:18 PM, Jeff Kelley wrote:
> I’m trying to use objc_msgSend_stret to call -bounds on a UIScreen. I have the following code:
>
>> SEL bounds = NSSelectorFromString(@"bounds");
>> CGRect screenBounds;
>> objc_msgSend_stret((void *)&screenBounds, screen, bounds);
>
> The declaration of objc_msgSend_stret in the Xcode code sense pop-up is as follows:
>
>> void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...);
>
> But that’s not what message.h would leave me to believe (with some unrelated lines removed):
>
>> #if defined(__OBJC2__)
>> OBJC_EXPORT void objc_msgSend_stret(id self, SEL op, ...);
>> #else
>> /* For compatibility with old objc-runtime.h header */
>> OBJC_EXPORT void objc_msgSend_stret(void * stretAddr, id self, SEL op, ...);
>> #endif
>
> So, if the declaration is actually the first (I’m compiling for iOS 4.2, so I’m pretty sure __OBJC2__ is defined), how do you use it and get the return value of the function?

Both declarations are wrong: you cannot and must not call them directly. The declaration of objc_msgSend_stret() cannot be expressed in C.

The correct way to call objc_msgSend_stret() or any other objc_msgSend() variant is to cast it to an appropriate function pointer type. Like this:

    CGRect (*msgSendFn)(id self, SEL _cmd);
    msgSendFn = (CGRect(*)(id, SEL))objc_msgSend_stret;
    CGRect screenBounds = msgSendFn(screen, @selector(bounds));

If the method had parameters, you would need to add them to the declaration of the function pointer variable.


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Multiple declarations of objc_msgSend_stret
      • From: Jeff Kelley <email@hidden>
References: 
 >Multiple declarations of objc_msgSend_stret (From: Jeff Kelley <email@hidden>)

  • Prev by Date: Multiple declarations of objc_msgSend_stret
  • Next by Date: Re: Multiple declarations of objc_msgSend_stret
  • Previous by thread: Multiple declarations of objc_msgSend_stret
  • Next by thread: Re: Multiple declarations of objc_msgSend_stret
  • Index(es):
    • Date
    • Thread