tags:

views:

358

answers:

1

At least the libsigc++2 project is hit by OS X headers defining nil on the preprocessor level, outside of namespaces etc. At least 10.5.5 and XCode 3.1 have this. Note that it is in effect not only in Objective-C sources but C++ as well.

Short question: why?

http://ardour.sourcearchive.com/documentation/2.5/functor__trait_8h-source.html

p.s. I remember nil from Objective-C, too. But I don't see a justification of such a blunt (imho) define for other languages, affecting code that has nothing to do with Objective-C at all (s.a. pure C++ projects).

+1  A: 

I'm using 10.5.6 and XCode 3.1.2. I just tried using nil on my pure cpp project, and it wasn't defined:

main.cpp:41: error: 'nil' was not declared in this scope

My guess is that your project is somehow including Cocoa or another Objective-C library. Perhaps your code is being compiled as Objective-C++? It can compile any combination of C++ and Objective-C, so existing C++ code may compile. This is the default for files with the .mm extension.

Did you create the XCode project for this library? If so, perhaps it is using XCode's prefix header that comes with the Framework template, which includes Cocoa/Cocoa.h. Check the "Prefix Header" option in the project and target info.

I also grepped through /usr/include, and didn't find any instances of #define nil.

[Edit: The .h file you linked to may #undef nil because it can also be used from Objective-C++.]

Jeff M