ifdef win32 linux,Is there an #ifdef ANDROID equivalent to #ifdef WIN32

33

Macro

Regarding predefined macros, there is the famous predef.sf.net.

Looking for Android brings up the devices page. There:

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

Examples

#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

If you want to include a code block for versions for a high enough version, you must first check for existence, and then you can do arithmetic comparisons:

#ifdef __ANDROID_API__

# if __ANDROID_API__ > 6

at least android 2.0.1

# else

less than 2.0.1

# endif

#endif

Multiple conditions

You can't do #ifdef FOO || BAR. The standard only defines the syntax

# ifdef identifier new-line

but you can use the unary operator defined:

#if defined(FOO) && defined(BAR)

you can also negate the result using !:

#if !defined(FOO) && defined(BAR)

this is included only if there is no FOO, but a BAR.

and of course there's a logical-or:

#if defined(FOO) || defined(BAR)

this is included if there is FOO or BAR (or both)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值