What are practical applications of weak linking?(弱链接的实际应用是什么?)
问题描述
使用特殊的编译器命令可以声明一个符号weak.根据维基百科:
Using special compiler commands a symbol can be declared weak. According to Wikipedia:
弱符号是目标文件或动态库中可能被其他符号定义覆盖的符号定义
a weak symbol is a symbol definition in an object file or dynamic library that may be overridden by other symbol definitions
在哪些场景或哪些应用中需要弱符号?有哪些典型用例?
In what scenarios or for what applications do you need weak symbols? What are typical use cases?
推荐答案
弱链接的一个用途是在 C++ 标准中实现 可替换 函数.即:
One use of weak linking is implementing the replaceable functions in the C++ standard. Namely:
void *operator new(std::size_t);
void *operator new(std::size_t, std::nothrow_t const &) noexcept;
void *operator new[](std::size_t);
void *operator new[](std::size_t, const std::nothrow_t&) noexcept;
void operator delete(void *) noexcept;
void operator delete(void *, std::nothrow_t const &) noexcept;
void operator delete[](void *) noexcept;
void operator delete[](void *, std::nothrow_t const &) noexcept;
这些是实现必须提供的功能,但如果程序实现了它们,那么程序的实现将替换或覆盖实现的版本.这很容易通过弱链接实现.
These are functions which must be provided by the implementation, but if a program implements them then the program's implementation replaces or overrides the implementation's version. This is easily implemented via weak linkage.
这篇关于弱链接的实际应用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:弱链接的实际应用是什么?


- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- C++ 协变模板 2021-01-01
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01