gpt4 book ai didi

c - 内置/内在测试

转载 作者:太空狗 更新时间:2023-10-29 16:54:06 26 4
gpt4 key购买 nike

我有一些使用 gcc 内部函数的代码。我想包含代码以防缺少内在函数。我该怎么做?

#ifdef __builtin_ctzll

不起作用。

最佳答案

使用最新版本的 clang,现在可以使用 __has_builtin() 宏检查是否存在内置内在函数,例如

int popcount(int x)
{
#if __has_builtin(__builtin_popcount)
return __builtin_popcount(x);
#else
int count = 0;
for (; x != 0; x &= x - 1)
count++;
return count;
#endif
}

希望 GCC 将来也能支持 __has_builtin()

关于c - 内置/内在测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4322352/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com