Created
October 28, 2011 19:11
-
-
Save bofh/1323181 to your computer and use it in GitHub Desktop.
Exploring @defs replacement in ObjC 2.0
This file contains hidden or 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
/* | |
* Compile with gcc -framework Foundation | |
*/ | |
#import <Foundation/Foundation.h> | |
struct internals { | |
int a; | |
int b; | |
}; | |
@interface Test : NSObject { | |
struct internals internals_; | |
} | |
- (void *)internals; | |
- (void)printInternals; | |
@end | |
@implementation Test | |
- (void *)internals | |
{ | |
return &internals_; | |
} | |
- (void)printInternals | |
{ | |
NSLog(@"a = %d\tb = %d", internals_.a, internals_.b); | |
} | |
@end | |
int main(void) | |
{ | |
Test *test = [Test new]; | |
struct internals *a; | |
a = [test internals]; | |
a->a = 1; | |
a->b = 2; | |
[test printInternals]; | |
NSLog(@"%p %p (%d)", test, a, (void *)a - (void *)test); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment