【发布时间】:2019-11-04 17:09:54
【问题描述】:
我有一个 .cpp 文件,它在多个地方都使用了 NULL。当我尝试在 Windows 机器 + 独立工具链上使用 clang++ 为 Android/x86 平台编译这个 cpp 文件时,我在使用 NULL 的地方遇到了“预期表达式”错误。我在 Android NDK 提供的 clang 标头的 stddef.h 中找到了 NULL 的定义,如下所示。
#if defined(__need_NULL)
#undef NULL
#ifdef __cplusplus
# if !defined(__MINGW32__) && !defined(_MSC_VER)
# define NULL __null
# else
# define NULL 0
# endif
#else
# define NULL ((void*)0)
#endif
据我所知,__null 是特定于 GNU 编译器的。就我而言,_MSC_VER 和 __MINGW32__ 都未定义,因为我正在使用 clang++ 和独立工具链为 Android 平台进行编译。所以它进入了define NULL __null。由于 clang++ 不知道__null 是什么,因此导致“预期表达式”错误。
我的问题是,为什么 clang 使用 GNU 编译器提供的宏(如 __null)?还是我在这里遗漏了什么?
谁能帮我理解。谢谢
【问题讨论】:
-
已经使用
nullptr.. -
什么独立的工具链?您也可以尝试添加
-D__MINGW32__看看它是否有效.. -
是的,确保没有人重新定义
__null
标签: android c++ android-ndk clang++ llvm-clang