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

标签 c++ stl

在我的标准库实现源文件中,我可以看到许多名称以 __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/

相关文章:

c++ - 为什么不能 static_cast 双空指针?

c++ - 模板类的 VS 编译器错误

linux - Visual Studio Express 2010 与 Linux gcc-4.3.2 上的 STL

c++ - 如何在 gdb 中转储 STL 容器数据?

c++ - 在一行中创建指向值的指针

android - 如何使用 Cmake 将 Android 项目与 libandroid 链接起来?

c++ - 是否有可能在 C++ 中使用 std::atomic_flag 获得线程锁定机制?

c++ - 如何 "inherit"来自 STL 类的迭代器?

c++ - C++返回集合的接口(interface)

c++ - 将 String^ 转换为 const char*