Created
July 14, 2013 14:41
-
-
Save markd2/5994487 to your computer and use it in GitHub Desktop.
Getting to the bottom of some odd compiler behavior.
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
| #import <Foundation/Foundation.h> | |
| // clang -g -Wall -framework Foundation -o trssnd trssnd.m | |
| @interface A : NSObject | |
| @property (assign, readonly, nonatomic) NSInteger blah; | |
| @property (assign, nonatomic) NSInteger hasIvar; | |
| @end // A | |
| @implementation A | |
| // Suppresses auto-synthesizing of an ivar. | |
| - (NSInteger) blah { | |
| return 23; | |
| } // blah | |
| @end // A | |
| // -------------------------------------------------- | |
| @interface B : A | |
| @property (assign, readwrite, nonatomic) NSInteger blah; | |
| @end // B | |
| @implementation B | |
| @end // B | |
| // -------------------------------------------------- | |
| int main (void) { | |
| B *b = [[B alloc] init]; | |
| NSLog (@"bork %ld", b->_hasIvar); | |
| NSLog (@"bork %ld", b->_blah); | |
| return 0; | |
| } // main | |
| #if 0 | |
| % clang -g -Wall -framework Foundation -o trssnd trssnd.m | |
| trssnd.m:46:28: error: instance variable '_hasIvar' is private | |
| NSLog (@"bork %ld", b->_hasIvar); | |
| ^ | |
| trssnd.m:48:28: error: 'B' does not have a member named '_blah' | |
| NSLog (@"bork %ld", b->_blah); | |
| ~ ^ | |
| 2 errors generated. | |
| #endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment