Skip to content

Instantly share code, notes, and snippets.

@rolfbjarne
Created November 7, 2016 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolfbjarne/783a83b9a04f7e167439c81c1e384305 to your computer and use it in GitHub Desktop.
Save rolfbjarne/783a83b9a04f7e167439c81c1e384305 to your computer and use it in GitHub Desktop.
// clang test.m -framework Foundation -otest -g && ./test
#include <stdio.h>
#include <objc/message.h>
#include <Foundation/Foundation.h>
int main ()
{
NSLog (@"64bit: %i", sizeof (void *) == 8);
NSString *str = [NSString alloc];
// crashes:
// str = objc_msgSend (str, @selector (initWithFormat:arguments:), @"%d", 123);
// crashes:
// void *array[1];
// array [0] = @"test";
//str = objc_msgSend (str, @selector (initWithFormat:arguments:), @"%@", array);
// works:
str = objc_msgSend (str, @selector (initWithFormat:), @"%@", @"test");
NSLog (@"%@", str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment