C/C++ MACOS、Windows、Linux、HarmonyOS 平台宏判断

本文提供经过三个平台一份代码编译无故障 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
相关推荐
Logic10111 分钟前
C语言/数据结构位运算题解:异或XOR找出多任务下载器中的“独特下载速度“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
2601_9622186112 分钟前
C++中decltype关键字的实现
开发语言·c++
朋友圈自动点赞工具29 分钟前
Gmail 委托邮箱在手机上关不掉
macos·智能手机·cocoa·硬件评测
繁华的地方不一定留下你的脚印1 小时前
C++ std::variant 与 std::visit:安全保存多种类型,写清每个处理分支
开发语言·c++
程序员老陆1 小时前
WIN32_LEAN_AND_MEAN:Windows 头文件里的“精简编译开关”
c++·windows
小黄人软件1 小时前
AndroidStudio老项目 macOS运行BlueTooth蓝牙串口助手(Android+Studio源码).rar
android·macos
hold?fish:palm2 小时前
45 二叉树的右视图
开发语言·c++·算法
MI_farmer2 小时前
Anaconda 安装在 D 盘但虚拟环境跑到 C 盘,以及 Conda PermissionError: WinError 5 的解决方法
c语言·开发语言·conda
ShineWinsu2 小时前
对于Redis:Redis的认识以及分布式系统的解析
linux·数据库·c++·redis·缓存·消息队列·分布式架构
布莱克6052 小时前
在C++中,构造函数能不能是虚函数?析构函数为什么要虚?
开发语言·c++·构造函数·析构函数·虚函数