设为首页 加入收藏

TOP

C/C++启动函数(三)
2014-11-24 00:43:33 来源: 作者: 【 】 浏览:202
Tags:C/C 启动 函数
mmandLine)) {
if (lpszCommandLine) {
lpszCommandLine++;
}
}
#endif /* _MBCS */
++lpszCommandLine;
}

/*
* Skip past any white space preceeding the second token.
*/
while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) {
lpszCommandLine++;
}

#ifdef WPRFLAG
mainret = wWinMain(
#else /* WPRFLAG */
mainret = WinMain(
#endif /* WPRFLAG */
(HINSTANCE)&__ImageBase,
NULL,
lpszCommandLine,
StartupInfo.dwFlags & STARTF_USESHOWWINDOW
StartupInfo.wShowWindow
: SW_SHOWDEFAULT
);
#else /* _WINMAIN_ */

#ifdef WPRFLAG
__winitenv = envp;
mainret = wmain(argc, argv, envp);
#else /* WPRFLAG */
__initenv = envp;
mainmainret = main(argc, argv, envp);
#endif /* WPRFLAG */

#endif /* _WINMAIN_ */

/*
* Note that if the exe is managed app, we don't really need to
* call exit or _c_exit. .cctor should be able to take care of
* this.
*/
if ( !managedapp )
exit(mainret);

if (has_cctor == 0)
_cexit();

}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/

mainret = GetExceptionCode();

/*
* Note that if the exe is managed app, we don't really need to
* call exit or _c_exit. .cctor should be able to take care of
* this.
*/
if ( !managedapp )
_exit(mainret);

if (has_cctor == 0)
_cexit();
} /* end of try - except */

return mainret;
}

我关心的是对于如下程序,类的构造和析构程序执行的时机:
[ html]
class CSayHello
{
public:
CSayHello()
{
cout<<"Constructor CSayHello"< }

~CSayHello()
{
cout<<"Deconstructor CSayHello"< }
};

CSayHello sayHello;

int main()
{
CSayHello sayHello1;
return 0;
}

很显然输出结果为:
[html]
Constructor CSayHello // 1
[html]
Constructor CSayHello // 2
[html]
Deconstructor CSayHello // 3
[html]
Deconstructor CSayHello // 4
第1句在__tmainCRTStartup中的_initterm( __xc_a, __xc_z )函数中输出
第2句进入main主函数后输出
第3句在执行到return 0时输出
第4句在退出main函数时,进入tmainCRTStartup函数中的exit函数中执行。

摘自 xudacheng06的专栏
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言基础考察 下一篇冒泡排序 Linux下c 实现

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: