Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了是否有#ifdef ANDROID等同于#ifdef WIN32大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些C代码有一堆#ifdef WIN32否则我们假设它的 IOS代码.不过我现在试图使用相同的c代码来安装一个 android端口.

对于#ifdef WIN32 ||有某种等价物ANDROID?

解决方法

关于预定义的宏,有着名的predef.sf.net.

寻找Android带来the devices page.有:

Type    | Macro           | Format  | Description
Version | __ANDROID_API__ | V       | V = API Version
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)

大佬总结

以上是大佬教程为你收集整理的是否有#ifdef ANDROID等同于#ifdef WIN32全部内容,希望文章能够帮你解决是否有#ifdef ANDROID等同于#ifdef WIN32所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。