我有一些c ++代码,有一堆#ifdef WIN32,否则我们假设它的IOS代码.但是我现在正试图将这个相同的c ++代码用于android端口.
#ifdef WIN32 ||是否有某种等价物 ANDROID?
Seb*_*ach 33
关于预定义的宏,有着名的predef.sf.net.
寻找Android会打开设备页面.那里:
Android的
必须从头文件中包含以下宏.
Type | Macro | Format | Description
Version | __ANDROID_API__ | V | V = API Version
Run Code Online (Sandbox Code Playgroud)
例
Android Version | __ANDROID_API__
1.0 | 1
1.1 | 2
1.5 | 3
1.6 | 4
2.0 | 5
2.0.1 | 6
2.1 | 7
2.2 | 8
2.3 | 9
2.3.3 | 10
3.0 | 11
Run Code Online (Sandbox Code Playgroud)
#ifdef __ANDROID__
# include <android/api-level.h>
#endif
#ifdef __ANDROID_API__
this will be contained on android
#endif
#ifndef __ANDROID_API__
this will NOT be contained for android builds
#endif
#if defined(WIN32) || defined(__ANDROID_API__)
this will be contained on android and win32
#endif
Run Code Online (Sandbox Code Playgroud)
如果要为足够高版本的版本包含代码块,则必须先检查是否存在,然后才能进行算术比较:
#ifdef __ANDROID_API__
# if __ANDROID_API__ > 6
at least android 2.0.1
# else
less than 2.0.1
# endif
#endif
Run Code Online (Sandbox Code Playgroud)
你做不到#ifdef FOO || BAR.该标准仅定义语法
# ifdef identifier new-line
Run Code Online (Sandbox Code Playgroud)
但你可以使用一元运算符defined:
#if defined(FOO) && defined(BAR)
Run Code Online (Sandbox Code Playgroud)
您也可以使用!以下方法否定结果:
#if !defined(FOO) && defined(BAR)
this is included only if there is no FOO, but a BAR.
Run Code Online (Sandbox Code Playgroud)
当然还有一个逻辑 - 或者:
#if defined(FOO) || defined(BAR)
this is included if there is FOO or BAR (or both)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15062 次 |
| 最近记录: |