静态变量的动态初始化阶段 [英] Dynamic initialization phase of static variables

查看:161
本文介绍了静态变量的动态初始化阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准明确规定静态持续时间变量(命名空间范围和类静态成员)的动态初始化不必在执行main之前发生:
这是实现定义的,无论动态初始化(8.5 ,9.4,12.1,12.6.1)的命名空间范围的对象在main的第一个语句之前完成。 IS 3.6.2(3)
是不是动态初始化是如何实现的?什么更好/更容易的方式来保证对象在使用前初始化?

The standard specifically states that dynamic initialization of static duration variables (namespace scope and class static members) does not have to occur before main is executed: "It is implementation-defined whether or not the dynamic initialization (8.5, 9.4, 12.1, 12.6.1) of an object of namespace scope is done before the first statement of main." IS 3.6.2(3) Is it not how dynamic initialization is [always?] implemented? What better/easier way to guarantee that the objects are initialized before use?

推荐答案

我相信这里的意图是允许动态加载库。

I believe the intention here is to allow dynamic load libraries.

在库中定义的静态变量不能保证在main之前被初始化,但必须在使用特定库中的任何东西之前发生。

Static variables defined in the libraries are not guaranteed to be initialized before main, but must happen before anything in the specific library is used.

这篇关于静态变量的动态初始化阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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