作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一些 C++ 代码,其中有一堆 #ifdef WIN32,否则我们假设它的 IOS 代码。但是,我现在正尝试将相同的 C++ 代码用于 Android 端口。
#ifdef WIN32 是否有某种等价物 ||安卓?
最佳答案
关于预定义宏,有著名的predef.sf.net .
寻找 Android 会出现 the devices page .那里:
Android
The following macros have to be included from the header file.
Type | Macro | Format | Description
Version | __ANDROID_API__ | V | V = API Version
Example
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
#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
如果要包含版本足够高版本的代码块,必须先检查是否存在,然后才能进行算术比较:
#ifdef __ANDROID_API__
# if __ANDROID_API__ > 6
at least android 2.0.1
# else
less than 2.0.1
# endif
#endif
你不能做 #ifdef FOO ||酒吧
。标准只定义语法
# ifdef identifier new-line
但您可以使用定义的一元运算符
:
#if defined(FOO) && defined(BAR)
您还可以使用 !
取反结果:
#if !defined(FOO) && defined(BAR)
this is included only if there is no FOO, but a BAR.
当然还有逻辑或:
#if defined(FOO) || defined(BAR)
this is included if there is FOO or BAR (or both)
关于android - 有没有等同于#ifdef WIN32 的#ifdef ANDROID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8475599/
判断这2个相似的Uris实际上相同的标准方法是什么? var a = new Uri("http://sample.com/sample/"); var b = new Uri("http://sam
这个问题在这里已经有了答案: Why does "true" == true show false in JavaScript? (5 个答案) 关闭 5 年前。 可能我很困惑,但我无法理解这个愚蠢
我是一名优秀的程序员,十分优秀!