简体   繁体   English

静态局部变量和静态局部对象初始化

[英]static local variable and static local object initialization

In VC++2008 there is a serious difference in initialization of static local variable and static local object. 在VC ++ 2008中,静态局部变量和静态局部对象的初始化存在严重差异。 Static local variable is initialized before main() and its definition statement within the function is skipped. 静态局部变量在main()之前初始化,并且其在函数中的定义语句被跳过。 Static local object is initialized by 0 value before main() and its definition statement within the function is executed only once . 静态局部对象在main()之前由0值初始化,并且其在函数中的定义语句仅执行一次。 Constructor is started and object is initialized by appropiate value. 启动构造函数,并通过适当的值初始化对象。 All that can be seen in Debug mode. 所有这些都可以在“调试”模式下看到。 Does this solution correspond to the existing C++ Standard? 此解决方案是否符合现有的C ++标准?

From http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf

Every object of static storage duration shall be zero-initialized at program startup before any other initialization takes place. 静态存储持续时间的每个对象都应在程序启动时进行零初始化,然后再进行其他初始化。 [ Note: in some cases, additional initialization is done later. [注意:在某些情况下,稍后会进行其他初始化。 —end note ] —尾注]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM