在main()之前运行什么? [英] What runs before main()?

查看:166
本文介绍了在main()之前运行什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在msvc8上测试之后,我发现:


  1. 解析GetCommandLine()到argc和argv

  2. 标准C库初始化

  3. C ++全局变量的构造方法


  1. 这个执行当我将程序移植到不同的编译器(gcc或armcc)或不同的平台时,顺序不同?

  2. 标准C库初始化有什么作用?到目前为止我知道setlocale()是必须的。

  3. 是否可以在全局变量的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:

  1. Parse GetCommandLine() to argc and argv
  2. Standard C Library initialization
  3. C++ Constructor of global variables

These three things are called before entering main().

My questions are:

  1. Will this execution order be different when I porting my program to different compiler (gcc or armcc), or different platform?
  2. What stuff does Standard C Library initialization do? So far I know setlocale() is a must.
  3. 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屋!

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