本文提供经过三个平台一份代码编译无故障 C/C++ 工程移植通过,所以无需担心宏在这些平台上面无法使用。
cpp
#include <stdio.h>
#include <stddef.h>
#if !defined(NULL)
#define NULL 0
#endif
#if defined(_DEBUG)
#if !defined(DEBUG)
#define DEBUG 1
#endif
#endif
#if defined(DEBUG)
#if !defined(_DEBUG)
#define _DEBUG 1
#endif
#endif
#if defined(_WIN64)
#if !defined(WIN64)
#define WIN64 1
#endif
#endif
#if defined(WIN64)
#if !defined(_WIN64)
#define _WIN64 1
#endif
#endif
#if defined(_WIN64)
#if !defined(_WIN32)
#define _WIN32 1
#endif
#endif
#if defined(_WIN32)
#if !defined(WIN32)
#define WIN32 1
#endif
#endif
#if defined(WIN32)
#if !defined(_WIN32)
#define _WIN32 1
#endif
#endif
#if defined(__linux__)
#if !defined(_LINUX)
#define _LINUX 1
#endif
#if !defined(LINUX)
#define LINUX 1
#endif
#elif defined(__APPLE__) && defined(__MACH__)
#if !defined(_MACOS)
#define _MACOS 1
#endif
#if !defined(MACOS)
#define MACOS 1
#endif
#endif
#if defined(__ANDROID__) || __ANDROID_API__ > 0
#if !defined(_ANDROID)
#define _ANDROID 1
#endif
#endif
#if defined(_ANDROID)
#if !defined(ANDROID)
#define ANDROID 1
#endif
#endif
#if defined(ANDROID)
#if !defined(_ANDROID)
#define _ANDROID 1
#endif
#endif
#if defined(_ANDROID)
#if !defined(_LINUX)
#define _LINUX 1
#endif
#if !defined(LINUX)
#define LINUX 1
#endif
#endif
#if defined(__harmony__)
#if !defined(_HARMONYOS)
#define _HARMONYOS 1
#endif
#endif
#if defined(_HARMONYOS)
#if !defined(HARMONYOS)
#define HARMONYOS 1
#endif
#endif
#if defined(HARMONYOS)
#if !defined(_HARMONYOS)
#define _HARMONYOS 1
#endif
#endif
#if ((defined(__IPHONE_OS_VERSION_MIN_REQUIRED)) || (defined(__APPLE__) && defined(__MACH__) && TARGET_OS_IOS))
#if !defined(_IPHONE)
#define _IPHONE 1
#endif
#if !defined(IPHONE)
#define IPHONE 1
#endif
#endif
#if defined(_WIN32)
#if defined(_MSC_VER) && defined(_M_IX86) && !defined(_M_IA64) && !defined(_M_X64)
#define __ORDER_LITTLE_ENDIAN__ 1
#define __ORDER_BIG_ENDIAN__ 0
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#elif defined(_MSC_VER) && (defined(_M_IA64) || defined(_M_X64))
#define __ORDER_LITTLE_ENDIAN__ 1
#define __ORDER_BIG_ENDIAN__ 0
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#else
#define __ORDER_LITTLE_ENDIAN__ 0
#define __ORDER_BIG_ENDIAN__ 1
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#endif
#endif