什么时候发生静态初始化? [英] When does static initialization occur?

查看:101
本文介绍了什么时候发生静态初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解C ++程序启动的方式是:


A.)在入口点之前发生的事情。

B.)在入口点和调用之间发生的事情

main()。

C.)main()。


因此,如果上述情况正常,在A或B期间是否会发生静态初始化?什么

发生在A?


John

The way I understand the startup of a C++ program is:

A.) The stuff that happens before the entry point.
B.) The stuff that happens between the entry point and the calling of
main().
C.) main().

So, if the above is OK, does static initialization occur during A or B? What
happens during A?

John

推荐答案

" JohnQ" ; < jo *********************** @ yahoo.com写道

新闻:FC ******** ********@newssvr19.news.prodigy.net:
"JohnQ" <jo***********************@yahoo.comwrote in
news:FC****************@newssvr19.news.prodigy.net :

我理解C ++程序启动的方式是:


A.)在入口点之前发生的事情。

B.)在入口点和调用之间发生的事情

main()。

C.)main()。


因此,如果上述情况正常,在A或
期间是否会发生静态初始化
B? A期间会发生什么?

John
The way I understand the startup of a C++ program is:

A.) The stuff that happens before the entry point.
B.) The stuff that happens between the entry point and the calling of
main().
C.) main().

So, if the above is OK, does static initialization occur during A or
B? What happens during A?

John



我认为主要是入口点。其他任何东西都是平台 -

具体。所以从标准的角度来看,我认为:


1)在main之前发生的事情
2)在主要事件中发生的事情

全局对象初始化为1.

I thought main was the entry point. Anything else would be platform-
specific. So from the Standard point of view, I thought:

1) The stuff that happens before main
2) The stuff that happens in main

Global objects are initialized in 1.


5月25日下午6:42,JohnQ < johnqREMOVETHISprogram ... @ yahoo.com>

写道:
On May 25, 6:42 pm, "JohnQ" <johnqREMOVETHISprogram...@yahoo.com>
wrote:

我理解C ++程序启动的方式是:


A.)在入口点之前发生的事情。

B.)在入口点和调用之间发生的事情

main()。

C.)main()。


因此,如果上述情况正常,则在A或A期间进行静态初始化B'什么

在A期间发生?

John
The way I understand the startup of a C++ program is:

A.) The stuff that happens before the entry point.
B.) The stuff that happens between the entry point and the calling of
main().
C.) main().

So, if the above is OK, does static initialization occur during A or B? What
happens during A?

John



main()是入口点。

答案取决于静态变量是否为本地变量(在

中,在第一次使用时构造的情况适用)。静态变量是一个类的成员吗?它被定义了吗?它是一个全局的(汇编

单位)?


您可能会通过常见问题获得一些见解:

[10.11 ]为什么带有静态数据成员的类得到链接器

错误?

[10.12]什么是静态初始化命令惨败?

[10.13]如何防止静态初始化命令惨败?

[10.15]如何防止静态初始化命令惨败?对于

我的静态数据成员?

http://www.parashift.com/c++-faq-lite/ctors.html

如果您仍需要澄清,请发布一个简单的例子。

main() is the entry point.
The answer depends on whether the static variable is local or not (in
which case Construct on First Use applies). Is the static variable a
member of a class? Was it defined? Is it a global (in a compilation
unit)?

You might gain some insight with the FAQ:
[10.11] Why are classes with static data members getting linker
errors?
[10.12] What''s the "static initialization order fiasco"?
[10.13] How do I prevent the "static initialization order fiasco"?
[10.15] How do I prevent the "static initialization order fiasco" for
my static data members?

http://www.parashift.com/c++-faq-lite/ctors.html

If you still need clarification, post a simple example.




" Salt_Peter" < pj ***** @ yahoo.comwrote in message

news:11 ********************** @ g4g2000hsf。 googlegro ups.com ...

"Salt_Peter" <pj*****@yahoo.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...

5月25日下午6:42,JohnQ < johnqREMOVETHISprogram ... @ yahoo.com>

写道:
On May 25, 6:42 pm, "JohnQ" <johnqREMOVETHISprogram...@yahoo.com>
wrote:

>我理解C ++程序启动的方式是:

A.)在入口点之前发生的事情。
B.)在入口点和
main()调用之间发生的事情。 /> C。)main()。

所以,如果上面没问题,A或B期间是否会发生静态初始化?
A期间发生了什么?

John
>The way I understand the startup of a C++ program is:

A.) The stuff that happens before the entry point.
B.) The stuff that happens between the entry point and the calling of
main().
C.) main().

So, if the above is OK, does static initialization occur during A or B?
What
happens during A?

John



main()是入口点。

答案取决于静态变量是否为本地变量(在

中哪种情况下构建首次使用适用)。静态变量是一个类的成员吗?它被定义了吗?它是一个全球性的(在汇编

单位)?


main() is the entry point.
The answer depends on whether the static variable is local or not (in
which case Construct on First Use applies). Is the static variable a
member of a class? Was it defined? Is it a global (in a compilation
unit)?



我一般都在询问,而不是特定的代码。我正在调用我的编译器调用入口点的

入口点。这是关键因为

它是我能够控制程序的第一个地方。但是如果我能做到这一点,我需要准备好接管那个创业阶段的职责




John

I was asking in general, not for a specific piece of code. I''m calling the
entry point that which my compiler calls the entry point. It is key because
it it the first place in time where I can get control of the program. But if
I do commandiere that point, I need to be prepared to take over the duties
of that phase of startup.

John


这篇关于什么时候发生静态初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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