全局static对象的构造函数调用时间问题
c++吧
全部回复
仅看楼主
level 12
v2abcd 楼主
c++保证进入main执行前,执行全部全局static对象的构造函数吗?
2013年04月14日 14点04分 1
level 12
v2abcd 楼主
还是大召唤一下吧
@幻 の上帝
@矮油不要酱紫哎 (打对没...[汗]
2013年04月14日 14点04分 2
@幻の上帝 @矮油不要酱紫唉
2013年04月14日 14点04分
2013年04月14日 15点04分
回复 v2abcd :没为此翻过标准,难以作答。好在楼下已经给出了答案
2013年04月14日 15点04分
level 12
ISO/IEC C++ N3485
3.6.2 Initialization of non-local variables [basic.start.init]
4
It is implementation-defined whether the dynamic initialization of a non-local variable with static storage
duration is done before the first statement of main. If the initialization is deferred to some point in time
after the first statement of main, it shall occur before the first odr-use (3.2) of any function or variable
defined in the same translation unit as the variable to be initialized.34
(Example 略)
2013年04月14日 15点04分 3
后面没那段没特殊字体的意思也就是说不能保证了?
2013年04月14日 15点04分
回复 v2abcd :字面意思。
2013年04月14日 15点04分
回复 LH_Mouse_Ex :[瀑布汗~]英文不太好,不敢确认...
2013年04月14日 15点04分
回复 v2abcd :保证在第一次“用”之前初始化。
2013年04月15日 03点04分
level 3
C++只保证在main执行前初始化完成,有一些全局的对象,在执行main之前就已经建好了。
2013年04月15日 09点04分 4
1