当前位置: 代码迷 >> C语言 >> 有关exit函数的问题
  详细解决方案

有关exit函数的问题

热度:419   发布时间:2007-09-26 17:39:10.0
有关exit函数的问题

在编程序时总能用到exit()函数其中exit(0)和exit(1)分别表示正常退出和非正常退出。但是我用exit编译时总提醒我warning: incompatible implicit declaration of built-in function 'exit'是怎么回事呢?是要包含一些头文件吗?

搜索更多相关的解决方案: exit  函数  

----------------解决方案--------------------------------------------------------

Terminate the calling process after cleanup (exit) or immediately (_exit).
void exit(
int status
);
void _exit(
int status
);
Parameter
status
Exit status.
Remarks
The exit and _exit functions terminate the calling process. exit calls, in last-in-first-out (LIFO) order, the functions registered by atexit and _onexit, then flushes all file buffers before terminating the process. _exit terminates the process without processing atexit or _onexit or flushing stream buffers. The status value is typically set to 0 to indicate a normal exit and set to some other value to indicate an error.
Although the exit and _exit calls do not return a value, the low-order byte of status is made available to the waiting calling process, if one exists, after the calling process exits. The status value is available to the operating-system batch command ERRORLEVEL and is represented by one of two constants: EXIT_SUCCESS, which represents a value of 0, or EXIT_FAILURE, which represents a value of 1. The behavior of exit, _exit, _cexit, and _c_exit is as follows.
FunctionDescription
exitPerforms complete C library termination procedures, terminates the process, and exits with the supplied status code.
_exitPerforms quick C library termination procedures, terminates the process, and exits with the supplied status code.
_cexitPerforms complete C library termination procedures and returns to the caller, but does not terminate the process.
_c_exitPerforms quick C library termination procedures and returns to the caller, but does not terminate the process.

When you call the exit or _exit functions, the destructors for any temporary or automatic objects that exist at the time of the call are not called. An automatic object is an object that is defined in a function where the object is not declared to be static. A temporary object is an object created by the compiler. To destroy an automatic object before calling exit or _exit, explicitly call the destructor for the object, as follows:
myObject.myClass::~myClass();
You should not call exit from DllMain with DLL_PROCESS_ATTACH. If you want to exit the DLLMain function, return FALSE from DLL_PROCESS_ATTACH.
Requirements
FunctionRequired headerCompatibility
exit<process.h> or <stdlib.h>ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_exit<process.h> or <stdlib.h>Win 98, Win Me, Win NT, Win 2000, Win XP


For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_exit.c
/* This program returns an exit code of 1. The
* error code could be tested in a batch file.
*/

#include <stdlib.h>

int main( void )
{
exit( 1 );
}

[此贴子已经被作者于2007-9-26 17:58:58编辑过]


----------------解决方案--------------------------------------------------------

太感谢百年老兄了!我是没有加#include <stdlib.h>头文件,我在linux上man exit为什么查不到呢?我在linux上应该怎么查这个函数呢?你写的这个我只是看懂了一个大概,可以用中文解释一下吗????


----------------解决方案--------------------------------------------------------
  相关解决方案