Skip to content

Instantly share code, notes, and snippets.

@OneSadCookie
Created January 23, 2012 23:21
Show Gist options
  • Save OneSadCookie/1666325 to your computer and use it in GitHub Desktop.
Save OneSadCookie/1666325 to your computer and use it in GitHub Desktop.
$ clang -fobjc-arc -O2 -arch x86_64 test.m -framework Foundation
$ ./a.out b: 0x104011710
Segmentation fault: 11
#import <Foundation/Foundation.h>
typedef void (^B)(void);
@interface A : NSObject
@end
@implementation A
- (NSArray *)f
{
B tmp = ^{
printf("a: %p\n", self);
};
return [NSArray arrayWithObjects:tmp, nil];
}
- (NSArray *)g
{
return [NSArray arrayWithObjects:^{
printf("b: %p\n", self);
}, nil];
}
@end
int main()
{
@autoreleasepool {
A *a = [A new];
((B)[[a g]objectAtIndex:0])();
((B)[[a f]objectAtIndex:0])();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment