gpt4 book ai didi

c++ - 标准库实现中 __builtin_ 前缀的含义是什么?

转载 作者:行者123 更新时间:2023-11-30 01:19:08 26 4
gpt4 key购买 nike

在我的标准库实现源文件中,我可以看到许多名称以 __builtin_ 为前缀的方法,即:__builtin_memmove。这是什么意思?这些方法在什么意义上是内置的?

template<bool _IsMove>
struct __copy_move<_IsMove, true, random_access_iterator_tag>
{
template<typename _Tp>
static _Tp*
__copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
{
__builtin_memmove(__result, __first,
sizeof(_Tp) * (__last - __first));
return __result + (__last - __first);
}
};

这些只是对二进制代码的调用吗?调试器无法进入它。

最佳答案

这只是编译器内部实现,对于gcc我们可以去他们的文档更好地理解它们:Other Built-in Functions Provided by GCC它说:

GCC provides a large number of built-in functions other than the ones mentioned above. Some of these are for internal use in the processing of exceptions or variable-length argument lists and are not documented here because they may change from time to time; we do not recommend general use of these functions.

The remaining functions are provided for optimization purposes.

GCC includes built-in versions of many of the functions in the standard C library. The versions prefixed with _builtin are always treated as having the same meaning as the C library function even if you specify the -fno-builtin option.

如果我们转到 Options Controlling C Dialect它说 -fno-builtin-function 标志(强调我的):

[...]GCC normally generates special code to handle certain built-in functions more efficiently; for instance, calls to alloca may become single instructions which adjust the stack directly, and calls to memcpy may become inline copy loops. The resulting code is often both smaller and faster, but since the function calls no longer appear as such, you cannot set a breakpoint on those calls, nor can you change the behavior of the functions by linking with a different library.[...]

对于 clang 你去 here .

关于c++ - 标准库实现中 __builtin_ 前缀的含义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21335360/

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