开发兼容、可移植、易扩展的程序
一 使用程序库中的宏
1 __cplusplus宏:判断是否是在C++环境中
#ifdef __cplusplus
#define INLINE_SPECIFIER inline
#else
#define INLINE_SPECIFIER static __inline
#endif
2 __GLIBC__
判断是否使用GNU c库。一般在unix(linux)环境下使用。
#ifdef __GLIBC__
#define HAS_ZERO 1
#endif
void zero(void* buf, int size)
{
#if defined(HAS_ZERO) && HAS_ZERO!=0 /*可以在预编译条件中判断一个宏的值*/
bzero(buf, size);
#else
memset(buf, 0, size);
#endif
}
3 使用下列宏来判断哪个平台的编译器
#if defined(_MSC_VER)
#elif defined(__GNUC__)
#elif defined(__CW32__)
#elif defined(__MWERKS__)
#elif defined(__GCCE__)
#elif defined(__ARMCC__)
#else
# error "Unknown compiler."
#endif

浙公网安备 33010602011771号