VC里面的exit(1);

2024-12-22 09:42:29
推荐回答(2个)
回答1:

exit(0) 正常中止程序 exit(非0) 非正常中止程序

回答2:

stdlib.h
Run-Time Library Reference
exit, _exit
Terminate the calling process after cleanup (exit) or immediately (_exit).
void exit(
int status
);
void _exit(
int status
);

Parameters
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.

Function Description
exit
Performs complete C library termination procedures, terminates the process, and exits with the supplied status code.

_exit
Performs quick C library termination procedures, terminates the process, and exits with the supplied status code.

_cexit
Performs complete C library termination procedures and returns to the caller, but does not terminate the process.

_c_exit
Performs 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:

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
Function Required header Compatibility
exit
or
ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_exit
or
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

Example
Copy Code
// crt_exit.c
// This program returns an exit code of 1. The
// error code could be tested in a batch file.

#include

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

.NET Framework Equivalent
System::Diagnostics::Process::Kill

See Also
Reference
Process and Environment Control
abort
atexit
_cexit, _c_exit
_exec, _wexec Functions
_onexit, _onexit_m
_spawn, _wspawn Functions
system, _wsystem
To make a suggestion or report a bug about Help or another feature of this product, go to the feedback site.