牛骨文教育服务平台(让学习变的简单)
博文笔记

linux下查看系统自身宏定义

创建时间:2017-06-19 投稿人: 浏览次数:2840

跨平台程序,经常要用到区分系统的宏定义,比如windows中的WIN32, WIN64, Linux中的 unix, linux等等系统自定义宏

那么在linux下面,怎么查看系统有哪些自定义宏咧,用如下方法:

$ touch dummy.hxx

$ cpp -dM ./dummy.hxx

输出如下:

[xhq@syfh1-10-0-128-229 server]$ cpp -dM ./dummy.hxx 
#define __DBL_MIN_EXP__ (-1021)
#define __FLT_MIN__ 1.17549435e-38F
#define __CHAR_BIT__ 8
#define __WCHAR_MAX__ 2147483647
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __FLT_EVAL_METHOD__ 0
#define __unix__ 1
#define __x86_64 1
#define __DBL_MIN_10_EXP__ (-307)
#define __FINITE_MATH_ONLY__ 0
#define __GNUC_PATCHLEVEL__ 7
#define __DEC64_MAX_EXP__ 385
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __UINTMAX_TYPE__ long unsigned int
#define __linux 1
#define __DEC32_EPSILON__ 1E-6DF
#define __unix 1
#define __LDBL_MAX_EXP__ 16384
#define __linux__ 1


要查看全部,可以加less命令:

$ cpp -dM ./dummy.hxx  |   less

就可以光标向上翻或者向下翻,因为系统可能宏定义比较多,一屏看不过来


以上原文地址:http://blog.csdn.net/xiaoheqin/article/details/52183073

另附上各操作系统的平台宏定义

AIX

Type Macro Description
Identification _AIX  
Version _AIX"VR" V = Version
R = Revision
Identification __TOS_AIX__ Defined by xlC
Example

If _AIX is defined, then the following macros can be used to determine the version. Notice that the macros indicates the mentioned version or higher. For example, if _AIX43 is defined, then _AIX41 will also be defined.

AIX Version Macro
3.2.x _AIX3
_AIX32
4.1 _AIX41
4.3 _AIX43

Android

Type Macro Format Description
Identification __ANDROID__    
Version __ANDROID_API__ V V = API Version

Must be included from <android/api-level.h>

Notice that Android is based on Linux, and that the linux macros also are defined for android.

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

Amdahl UTS

Type Macro
Identification UTS

AmigaOS

Type Macro Description
Identification AMIGA  
Identification __amigaos__ Defined by GNU C

Apollo AEGIS

Type Macro
Identification aegis

Apollo Domain/OS

Type Macro
Identification apollo

Bada

Based on Nucleus OS.

BeOS

Type Macro
Identification __BEOS__

Blue Gene

Type Macro Description
Identification __bg__ All Blue Gene systems

Defined by XL C/C++ and GNU C
Version __bgq__ Blue Gene/Q

Defined for XL C/C++ and GNU C
Identification __THW_BLUEGENE__ All Blue Gene systems

Defined by XL C/C++
Version __TOS_BGQ__ Blue Gene/Q

Defined by XL C/C++

BSD Environment

Type Macro Format Description
Identification __FreeBSD__
__NetBSD__
__OpenBSD__
__bsdi__
__DragonFly__
   
Version BSD YYYYMM YYYY = Year
MM = Month

Must be included from <sys/param.h>
Version BSD4_2
BSD4_3
BSD4_4
  Must be included from <sys/param.h>
Identification _SYSTYPE_BSD   Defined by DEC C
Example
Version BSD Macro
4.3 Net2 199103  
4.4 199306 BSD4_4
4.4BSD-Lite2 199506  

BSD/OS

Type Macro
Identification __bsdi__

ConvexOS

Type Macro
Identification __convex__

Cygwin Environment

Type Macro
Identification __CYGWIN__

DG/UX

Type Macro
Identification DGUX
Identification __DGUX__
Identification __dgux__

DragonFly

Type Macro
Identification __DragonFly__

DYNIX/ptx

Type Macro
Identification _SEQUENT_
Identification sequent

eCos

Type Macro
Identification __ECOS

EMX Environment

Type Macro
Identification
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。