什么是弱链接的实际应用? [英] What are practical applications of weak linking?

查看:140
本文介绍了什么是弱链接的实际应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用特殊的编译器指令,符号可以申报的的。 根据维基百科

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.

这篇关于什么是弱链接的实际应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆