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.
这篇关于弱链接的实际应用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:弱链接的实际应用是什么?
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- c++ STL设置差异 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
