Skip to content

Instantly share code, notes, and snippets.

@below
Created September 24, 2014 14:19
Show Gist options
  • Save below/1192cb4cb613c13c3e54 to your computer and use it in GitHub Desktop.
Save below/1192cb4cb613c13c3e54 to your computer and use it in GitHub Desktop.
objc_msgSend
- (void) bar {
SEL selector = @selector(foo);
typedef void (send_type) (id, SEL);
send_type func = (send_type)objc_msgSend();
func (self, selector);
}
foobar.m:25:22: error: used type 'send_type' (aka 'void (__strong id, SEL)') where arithmetic or pointer type is required
send_type func = (send_type)objc_msgSend();
^ ~~~~~~~~~~~~~~
1 error generated.
This is pretty much the code given in Session 417, page 14:
http://devstreaming.apple.com/videos/wwdc/2014/417xx2zsyyp8zcs/417/417_whats_new_in_llvm.pdf?dl=1
@elland
Copy link

elland commented Sep 24, 2014

Try:

((return_type (*) (id, SEL, arg1, arg2, ...))objc_msgSend)(target, selector, arg1, arg2, ...);

@macguru
Copy link

macguru commented Sep 24, 2014

send_type func = (send_type)objc_msgSend;

leave out the ()

@below
Copy link
Author

below commented Sep 24, 2014

@elland That works!

@macguru: That does not seem to work

foobar.m:25:22: error: used type 'send_type' (aka 'void (__strong id, SEL)') where arithmetic or pointer type is required
send_type func = (send_type)objc_msgSend;
^ ~~~~~~~~~~~~
1 error generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment