views:

112

answers:

3

When development various platforms(Android,iPhone,Mac,Windows and so on), it is necessary diverged processing(#ifdef/#endif) by depends on an platform definition. But, I don't know original definition in Mac/iPhone/Android.

 Windows : WIN32 (Visual C++)

 Mac : __MAC_NA(?) (XCode)

 iPhone/iPad/iPod : __IPHONE_NA(?) (XCode)

 Android : ?? (AndroidNDK)

By what definition should I divide?

+1  A: 

Hi,

Android NDK uses definition ANDROID.

ognian
+3  A: 

For iPhone, I believe the define is TARGET_OS_IPHONE and for Android it's ANDROID. I'm not too familiar with Apple-specific stuff, but after poking around I found a great list for tons of OS defines here. There's another answer here on SO that has a method for pulling the defines out, found here

Gemini14
That's good point.TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR defined was exist.>>Android it's ANDROIDOh, it could divide by ANDROID defined. Thanks.
Shiva
It defined it as follows. [ANDROID -> Android][TARGET_OS_IPHONE or TARGET_IPHONE_SIMULATOR -> iPhone/iPad/iPodTouch][WIN32 -> Windows][When TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR is not define and __APPLE__ is defined -> Mac][Otherwise -> Unix or Linux]
Shiva
+4  A: 

You could always make some up for your projects, thereby freeing yourself from compiler/platform specific defines.

  • Android: #define PLATFORM_ANDROID
  • Iphone: #define PLATFORM_IPHONE
  • etc.

And have all builds include a configuration file that defines one of these macros in a given project and that should work across the board. If you're using Visual Studio, you can just define these in the Project Settings without even needing a configuration file.

zdawg
This is really the only safe, clean way to do it. I've seen the alternative in several programs (GNU screen is the worst I can think of) and it becomes a nightmare. Not to mention, if your code is testing any macro definition that begins with _ which isn't explicitly defined in the C standard, it has unspecified behavior.Aside from this, you really should avoid testing for platforms and assuming presence/absence of features based on the platform. Platforms change a lot over time. It's much better to test for specific features you want to use and have something like `#ifdef HAVE_FOO`.
R..
Uh, huh. I see.When development in linux OS like ubuntu, the way seems to be good. Thanks!
Shiva