Implicitly declaring library function ' objc_msgsend ' with type ' (Id,sel,...) ' Warning

Source: Internet
Author: User

I've been using objc_msgsend, but I didn't notice Apple's documentation, so suddenly objc_msgsend crash. There is no problem with the previous 32 bits, and then the exc_bad_access problem occurs after converting to 64 bits. Of course Apple re-documentation ([64-bit Transition Guide for Cocoa Touch] (https://developer.apple.com/library/prerelease/ios/ Documentation/general/conceptual/cocoatouch64bitguide/convertingyourappto64-bit/convertingyourappto64-bit.html #//apple_ref/doc/uid/tp40013501-ch3-sw26)) also mentions: Dispatch objective-c Messages Using the Method Function ' s Prototypean Exception to the casting rule described above was when you were calling the Objc_msgsend function or any other similar funct Ions in the OBJECTIVE-C runtime that send messages. Although the prototype for the message functions have a variadic form, the method function that's called by the objective- C runtime does not share the same prototype. The OBJECTIVE-C runtime directly dispatches to the function that implements the method, so the calling conventions is MIS Matched, as described previously. Therefore must cast the Objc_msgsend function to a prototype thaT matches the method function being called. Listing 2-14 shows the proper form for dispatching a message to an object using the low-level message functions. In this example, the Dosomething:method takes a single parameter and does not has a variadic form. It casts the Objc_msgsend function using the prototype of the method function. Note that the A method function always takes an ID variable and a selector as its first and a parameters. After the Objc_msgsend function was cast to a function pointer, the call is dispatched through that same function pointer you must The prototype must be defined before it can be used, so that the crash ID fun (int x,id y,...) does not occur; ID (*action) (int,id) = (ID (*) (Int,id)) fun;action (1,@ "s"); if no return value ID is changed to void the original we wrote: Objc_msgsend (self, @selector ( DoSomething:), 0); According to Apple's specification:-(int) dosomething: (int) x {...}    -(void) dosomethingelse {int (*action) (ID, sel, int) = (int (*) (ID, sel, int)) Objc_msgsend; Action (self, @selector (dosomething:), 0);} Final simplification after 64-bit invocation: ((void (*) (ID, sel,int)) objc_msgsend) (Self, @selector (dosomething:), 0); 

Original: Http://blog.iloss.me/post/kai-fa/2014-12-09-objc_msgsend?action=show_raw

Implicitly declaring library function ' objc_msgsend ' with type ' (Id,sel,...) ' Warning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.