我想找exit函数的定义

lettermail6 2003-09-11 04:26:07
我想找exit函数的定义,打开stdlib.h文件void
只找到下面相关东西,void _Cdecl exit(int __status);
请问1. _Cdecl 是什么东西?
stdlib.h里面始终也没有 函数exit()的定义, 请问定义(函数体)在哪里?


#include<iostream.h>
#include<stdlib.h>
main()
{int i,j,flag=1;
cin>>i;
if(i==3)
exit(1); //??exit(1) 与exit(0) 一样的.
cout<<"kk";

}
...全文
267 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cwanter 2003-09-11
  • 打赏
  • 举报
回复
exit链接时的代码在LIBC.LIB中。不过VC6.0提供了它的源代码。在Microsoft Visual Studio\VC98\CRT\SRC\crt0dat.c中。这些代码在VC6.0安装盘上都有~

static void __cdecl doexit (int code, int quick, int retcaller);

void __cdecl exit (
int code
)
{
doexit(code, 0, 0); /* full term, kill process */
}


static void __cdecl doexit (
int code,
int quick,
int retcaller
)
{
#ifdef _DEBUG
static int fExit = 0;
#endif /* _DEBUG */

#ifdef _MT
_lockexit(); /* assure only 1 thread in exit path */
#endif /* _MT */

if (_C_Exit_Done == TRUE) /* if doexit() is being called recursively */
TerminateProcess(GetCurrentProcess(),code); /* terminate with extreme prejudice */
_C_Termination_Done = TRUE;

/* save callable exit flag (for use by terminators) */
_exitflag = (char) retcaller; /* 0 = term, !0 = callable exit */

if (!quick) {

/*
* do _onexit/atexit() terminators
* (if there are any)
*
* These terminators MUST be executed in reverse order (LIFO)!
*
* NOTE:
* This code assumes that __onexitbegin points
* to the first valid onexit() entry and that
* __onexitend points past the last valid entry.
* If __onexitbegin == __onexitend, the table
* is empty and there are no routines to call.
*/

if (__onexitbegin) {
_PVFV * pfend = __onexitend;

while ( --pfend >= __onexitbegin )
/*
* if current table entry is non-NULL,
* call thru it.
*/
if ( *pfend != NULL )
(**pfend)();
}

/*
* do pre-terminators
*/
_initterm(__xp_a, __xp_z);
}

/*
* do terminators
*/
_initterm(__xt_a, __xt_z);

#ifndef CRTDLL
#ifdef _DEBUG
/* Dump all memory leaks */
if (!fExit && _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & _CRTDBG_LEAK_CHECK_DF)
{
fExit = 1;
_CrtDumpMemoryLeaks();
}
#endif /* _DEBUG */
#endif /* CRTDLL */

/* return to OS or to caller */

if (retcaller) {
#ifdef _MT
_unlockexit(); /* unlock the exit code path */
#endif /* _MT */
return;
}


_C_Exit_Done = TRUE;

ExitProcess(code);


}

MiracleNo1 2003-09-11
  • 打赏
  • 举报
回复
SGI有C++ STL 的下载不知道是不是也有C的实现库的下载据说VC中有可选安装的库的源码,我没用过。
fanqing 2003-09-11
  • 打赏
  • 举报
回复
.h中的只是声明,定义在.obj文件中。你是看不到的。除非有什么反编译的软件。
zxm954712 2003-09-11
  • 打赏
  • 举报
回复
It is a binary file and file name is LIBC.LIB
lettermail6 2003-09-11
  • 打赏
  • 举报
回复
to : 三剑绝
Now that the function body of exit exist in the library , which file dose the function body of exit exist?
why can i not see and read the file, if I know which file it exist , then i can open it and read it
B828 2003-09-11
  • 打赏
  • 举报
回复
函数体在已经在一个.obj文件中,在你进行连接的时候,集成开发环境自动的把这一段函数的代码连接到你的程序中(以上只对于静态连接而言)。

如果是动态连接,连接程序仅仅把该函数的入口地址加入到你的程序。
zxm954712 2003-09-11
  • 打赏
  • 举报
回复
The function body of exit exist in the library file and you don't see it.
you can only read its declaration and not definition.

about _Cdecl is function calling method and it is same as _stdcall

csdnxw 2003-09-11
  • 打赏
  • 举报
回复
exit中的参数是程序退出时返回给操作系统的退出码,
在自己的程序中很少用到。

下面是exit在C++ Builder中的定义
Header File : stdlib.h

Category : Process Control Routines

Prototype :void exit(int status);

Description Terminates program.

exit terminates the calling process. Before termination, all files are closed, buffered output (waiting to be output) is written, and any registered "exit functions" (posted with atexit) are called.

status is provided for the calling process as the exit status of the process. Typically a value of 0 is used to indicate a normal exit, and a nonzero value indicates some error. It can be, but is not required, to be set with one of the following:

EXIT_FAILURE Abnormal program termination; signal to operating system that program has terminated with an error
EXIT_SUCCESS Normal program termination

Return Value

None.

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧