gpt4 book ai didi

c++ - "class _LIBCPP_TEMPLATE_VIS vector"中宏_LIBCPP_TEMPLATE_VIS的用法是什么

转载 作者:行者123 更新时间:2023-11-30 05:03:57 24 4
gpt4 key购买 nike

像标准库类vector,声明总是这样“类 _LIBCPP_TEMPLATE_VIS vector ”。

https://github.com/llvm-mirror/libcxx/blob/7102892bf3dfffb3f988aa9a0a29f58171a508d7/include/__config#L717

不知道为什么在类关键字和类名之间插入宏。

最佳答案

这是一个符号可见性宏。它存在的原因是确保 -fvisibility=hidden 编译标志不会影响 std::vector ABI。使用 Clang,它扩展为 __attribute__((__visibility__("default")))。该宏允许它适应不同的编译器/平台,如 documentation 中所述。 :

Libc++ uses various “visibility” macros in order to provide a stableABI in both the library and the headers. These macros work by changingthe visibility and inlining characteristics of the symbols they areapplied to.

_LIBCPP_TEMPLATE_VIS

Mark a type’s typeinfo and vtable as having default visibility. Thismacro has no effect on the visibility of the type’s member functions.

GCC Behavior: GCC does not support Clang’s type_visibility(…)attribute. With GCC the visibility(…) attribute is used and memberfunctions are affected.

Windows Behavior: DLLs do not support dllimport/export on classtemplates. The macro has an empty definition on this platform.

另见 GCC visibility文档。

关于c++ - "class _LIBCPP_TEMPLATE_VIS vector"中宏_LIBCPP_TEMPLATE_VIS的用法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49140528/

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