Created
November 13, 2014 07:52
-
-
Save OneSadCookie/234a40cb13e80adc7b1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014-11-13 20:51:24.187 a.out[78021:7001297] int, immediate call of block | |
2014-11-13 20:51:24.188 a.out[78021:7001297] 42 | |
2014-11-13 20:51:24.564 a.out[78025:7001307] int, block called after return | |
2014-11-13 20:51:24.565 a.out[78025:7001307] 42 | |
2014-11-13 20:51:24.921 a.out[78029:7001313] NSString, immediate call of block | |
2014-11-13 20:51:24.922 a.out[78029:7001313] 42 | |
2014-11-13 20:51:25.295 a.out[78033:7001323] NSString, block called after return | |
2014-11-13 20:51:25.297 a.out[78033:7001323] (null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cc -DINTS -DIMMEDIATECALL -Os -fobjc-arc -framework Foundation test.m && ./a.out | |
cc -DINTS -Os -fobjc-arc -framework Foundation test.m && ./a.out | |
cc -DIMMEDIATECALL -Os -fobjc-arc -framework Foundation test.m && ./a.out | |
cc -Os -fobjc-arc -framework Foundation test.m && ./a.out | |
rm a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface Foo : NSObject | |
@property (readwrite, copy) void (^blockprop)(); | |
@end | |
#if defined(INTS) | |
typedef int error_t; | |
static int _error = 42; | |
static int *error = &_error; | |
static inline void showerror(error_t *e) | |
{ | |
NSLog(@"%d", *e); | |
} | |
#else | |
typedef NSString error_t; | |
static NSString *error = @"42"; | |
static inline void showerror(error_t *e) | |
{ | |
NSLog(@"%@", e); | |
} | |
#endif | |
@implementation Foo | |
- (id)initWithError:(error_t **)errorHandle; | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
self.blockprop = ^{ | |
*errorHandle = error; | |
}; | |
#if defined(IMMEDIATECALL) | |
self.blockprop(); | |
#endif | |
} | |
return self; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool | |
{ | |
NSLog( | |
@"%s, %s", | |
#if defined(INTS) | |
"int", | |
#else | |
"NSString", | |
#endif | |
#if defined(IMMEDIATECALL) | |
"immediate call of block" | |
#else | |
"block called after return" | |
#endif | |
); | |
error_t *e = 0; | |
Foo *foo = [[Foo alloc] initWithError:&e]; | |
#if !defined(IMMEDIATECALL) | |
foo.blockprop(); | |
#endif | |
showerror(e); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment