Please look into this header:
// Test.h
@interface Test : NSObject @end
extern id A; // (0)
//extern static id B; // (1) Uncomment to get a compiling error
extern id C; // (2)
//extern static id D; // (3) Uncomment to get a compiling error
And into this implementation:
// Test.m
#import "Test.h"
id A = @"A"; // (4)
static id B = @"B"; // (5)
@implementation Test
id C = @"C"; // (6)
static id D = @"D"; // (7)
@end
// Still Test.m
@interface Test2 : NSObject @end
@implementation Test2 : NSObject
+ (void)initialize {
NSLog(@"%@ %@", A, B); // (8)
NSLog(@"%@ %@", C, D); // (9)
}
@end
I have the following questions:
- Is there any fundamental difference between declarations (4) and (5) or (6) and (7)?
- Is there any difference between the “external” declaration (4) and the enclosed into implementation scope (6)?
- Why (6) and (7) declared within implementation scope can be accessed in another implementation scope (9)?
- Why (2) declared in header can access (6) declared within implementation scope?
- Why (1) and (3) generate errors
Cannot combine with previous 'extern' declaration specifier, but (0) and (2) are compiled with no errors?