關於預定義的宏,有著名的predef.sf.net 。

尋找Android帶來了的設備頁面。 這裡:Android

下列宏必須包含在頭文件中。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

#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 || BAR 該標準僅定義語法# ifdef identifier new-line

但是你可以使用一元運算符 defined:#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)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐