Martin Schlott
Martin Schlott

Reputation: 4547

Is there a define like __APPLE__ for Objective C/C++

I got a little C++ helper file which has some support functions for std::strings. As I use it in ".cpp" files and in ".mm" files, I want to add some Objective C++ helper functions. Now I search for a define like:

#ifdef __APPLE__
#ifdef __I_AM_INCLUDED_IN_A_MM_FILE__
// define some Objective C++ code here
#endif
#endif

Is there a define? Is there a list of XCode defines?

Upvotes: 2

Views: 1621

Answers (1)

Paul R
Paul R

Reputation: 212969

__OBJC__ and __OBJC2__ are defined when compiling a .mm file.

For future reference you can test for things like this as follows:

$ clang -dM -E foo.mm > mm.txt
$ clang -dM -E foo.cpp > cpp.txt
$ sdiff -s mm.txt cpp.txt
#define IBAction void)__attribute__((ibaction)                <
#define IBOutlet __attribute__((iboutlet))                    <
#define IBOutletCollection(ClassName) __attribute__((iboutlet <
#define OBJC_ZEROCOST_EXCEPTIONS 1                            <
#define __NEXT_RUNTIME__ 1                                    <
#define __OBJC2__ 1                                           <
#define __OBJC__ 1                                            <

(note that foo.mm and foo.cpp are just empty files)

Upvotes: 7

Related Questions