开发者

Macro definition in cross-platform

开发者 https://www.devze.com 2023-01-06 09:20 出处:网络
When development various platforms(Android,iPhone,Mac,Windows and so on), it is necessary diverged processing(#ifdef/#endif) by depends on an platform definition.

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?


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


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.


Android NDK uses definition ANDROID.

0

精彩评论

暂无评论...
验证码 换一张
取 消