在main()之前运行什么? [英] What runs before main()?
问题描述
在msvc8上测试之后,我发现:
- 解析GetCommandLine()到argc和argv
- 标准C库初始化
- C ++全局变量的构造方法
- 这个执行当我将程序移植到不同的编译器(gcc或armcc)或不同的平台时,顺序不同?
- 标准C库初始化有什么作用?到目前为止我知道setlocale()是必须的。
- 是否可以在全局变量的C ++构造函数中调用标准C函数?
1:当我将程序移植到不同的编译器(gcc或armcc)时,不同的平台?
是的。
2:什么东西标准C库初始化?到目前为止我知道setlocale()是必须的。
我确定还有其他东西。在main启动后,你不应该依赖任何全局对象util。这意味着像std streams(std :: cin,std :: cout)这样的东西可能不可用。
3:调用全局变量的C ++构造函数中的标准C函数?
可能不是。
After testing on msvc8, I found:
- Parse GetCommandLine() to argc and argv
- Standard C Library initialization
- C++ Constructor of global variables
These three things are called before entering main().
My questions are:
- Will this execution order be different when I porting my program to different compiler (gcc or armcc), or different platform?
- What stuff does Standard C Library initialization do? So far I know setlocale() is a must.
- Is it safe to call standard C functions inside C++ constructor of global variables?
1: Will this execution order be different when I porting my program to different compiler (gcc or armcc), or different platform?
Yes.
2: What stuff does Standard C Library initialization do? So far I know setlocale() is a must.
I am sure there is other stuff. You should not rely on any global objects util after main has started. This means things like std streams (std::cin, std::cout) may not be usable.
3: Is it safe to call standard C functions inside C++ constructor of global variables?
Probably not.
这篇关于在main()之前运行什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!