nil
is not a keyword. nil
is defined in objc.h [on Mac OS X] (and __DARWIN_NULL
is really just NULL
):
#ifndef nil
#define nil __DARWIN_NULL /* id of Nil instance */
#endif
That is, nil
isn't really part of the compiled language, but a convention used during compilation that is perpetuated by the system libraries.
Splitting hairs, obviously. You really could compile Objective-C source without nil
, though.
It is akin to asking "Can I write a tool that has variables named deflate
while still using the zlib.h
interface?". Sure. But it'll be ugly.
And, in fact, the compiler does not automatically include objc.h. This:
#include <stdio.h>
int main() {
int nil = 5;
fprintf(stdout, "Hello %d\n", nil);
return 0;
}
Compiles and runs just fine in a standard Foundation tool project (in the main.m) once you remove the precompiled/prefix header that imports Foundation and, hence, objc.h. (So, yes, out of the box, the Xcode templates do cause objc.h
to be imported by way of importing Cocoa/Cocoa.h
or Foundation/Foundation.h
.)