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的专栏
|