本文介绍了动态库破坏C ++标准吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++标准 3.6.3 表示



静态持续时间的初始化对象的析构函数main



在Windows上,您可以使用 FreeLibrary 和linux dlclose 以卸载动态链接库。你可以在从main返回之前调用这些函数。



卸载共享库的副作用是运行库中定义的静态对象的所有析构函数。



这是否意味着它违反了C ++标准,因为这些析构函数已经过早运行?解决方案

如果你非常努力这样做,它们只会过早运行 - 默认行为是标准符合。


The C++ standard 3.6.3 states

Destructors for initialized objects of static duration are called as a result of returning from main and as a result of calling exit

On windows you have FreeLibrary and linux you have dlclose to unload a dynamically linked library. And you can call these functions before returning from main.

A side effect of unloading a shared library is that all destructors for static objects defined in the library are run.

Does this mean it violates the C++ standard as these destructors have been run prematurely ?

解决方案

They are only run prematurely if you go to great effort to do so - the default behavior is standard conforming.

这篇关于动态库破坏C ++标准吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 06:02