c - 如何检查 __builtin_ 函数在 gcc 上是否可用
问题描述
我需要知道 gcc 是否有一种方法来检查那些真棒的存在__builtin_MY_DESIRED_FUNCTIONs
例如,我想使用__builtin_nan
并确保它可用于我的程序,并且在编译期间不会失败。
我会更具体地说:在clang上有__has_builtin
“检查器”,所以我们可以这样写
#if __has_builtin(__builtin_nan)
但我找不到 gcc 的模拟。
也许我可以只依赖 gcc,比如“哦,我现在使用 gcc,让我们假设所有这些__builtin_
都在这里,如下面的示例......”
#if __GNUC__
double mynan = __builtin_nan("0");
#endif
也许它会起作用,直到有人把这个“-fno-builtin”编译标志。
解决方案
No, you will have to use __GNUC__
and __GNUC_MINOR__
(and __GNUC_PATCHLEVEL__
if you use such gcc versions) to test for each release specific builtin function (gcc releases can be found here)
For example:
/* __builtin_mul_overflow_p added in gcc 7.4 */
#if (__GNUC__ > 7) || \
((__GNUC__ == 7) && (__GNUC_MINOR__ > 3))
#define BUILTIN_MUL_OVERFLOW_EXIST
#endif
#ifdef BUILTIN_MUL_OVERFLOW_EXIST
int c = __builtin_mul_overflow_p (3, 2, 3) ? 0 : 3 * 2;
#endif
And there is an open bug for exactly what you are asking about, in here.
推荐阅读
- css - 如何让到处下雨?
- c++ - 创建从 Variadic Template Pack 派生的类型的元组
- r - 将向量重命名为向量名称和 df 名称的混合
- python - Pandas 的条件平均值
- c# - C# 后台工作人员 - 我应该同时使用多少?
- c# - 使用 Enumerable.Repeat 进行容量列表初始化的问题
- python - 自动将 `stackedWidget` 页面的高度调整为放置在其上的小部件的高度
- flutter - 如何制作一个看起来像这样在颤动中弹出的按钮
- scala - 使用 Spark ML 计算 PCA 时出现 IllegalArgumentException
- python - 请求非常慢,有时会返回错误