Is special meaning of C statements inside of Objective-C class sections documented anywhere?

There are quite a few features a C function acquires when defined inside of the @implementation block of an Objective-C class, e.g. it can be accessed before declared:

@implementation TDWClass

- (void)method {
    bar(); // the function is accessible here despite not being declared in the code before
}

void bar(void) {
    NSLog(@"Test");
}

@end

Plus it is granted access to the private ivars of the class:

@implementation TDWClass {
@private
    int _var;
}

- (void)foo {
    bar(self);
}

void bar(TDWClass *self) {
    self->_var += 2; // a private instance variable accessed
}

@end

Some sources also say that static variables inside of @implementantion section had special meaning (unlike C static they were private to the enclosing class, not the compilation unit), however I could not reproduce this on my end.

Having that said, almost all such features were either deduced or found on third-party sources. I wonder if anything like that is/had ever been documented anywhere, so i can read through full list or special meanings of C statements inside of Objective-C class sections?

Replies

I could not reproduce this on my end.

Yeah, that one doesn’t gel with my experience.

I wonder if anything like that is/had ever been documented anywhere, so i can read through full list or special meanings of C statements inside of Objective-C class sections?

The go-to doc for this sort of thing is The Objective-C Programming Language but I don’t things it covers either of the points you mentioned.

The other place I look for docs about weird edge cases is the Clang documentation, specifically the Objective-C Features doc but, again, I don’t think it’s covered there either.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Does it mean, that we cannot reliably say this features will hold in future releases, and this is rather implementation-dependent detail?

Add a Comment