经常看到exit(1),exit(-1),exit(0),exit(status)的参数到底各代表啥意思?

booming 2005-01-01 04:37:38
经常看到exit(1),exit(-1),exit(0),exit(status)的参数到底各代表啥意思?
...全文
3593 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
angelcool 2005-01-02
  • 打赏
  • 举报
回复
知识
liudaqin 2005-01-02
  • 打赏
  • 举报
回复
学习
guangsan 2005-01-01
  • 打赏
  • 举报
回复
就是一个指定的进程退出代码。如果是一个单一的程序,status是0,-1,1都一样使程序退出(不知道这个退出代码如何处理)。

如果是一个子进程,可以使用GetExitCodeProcess获得退出代码,然后进行处理。



但是在面向对象的环境中由于exit()和abort()不销毁对象请不要在面向对象环境中使用abort()和exit()。
hiiiiiijiang 2005-01-01
  • 打赏
  • 举报
回复
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.


Example

/* EXITER.C: This program prompts the user for a yes
* or no and returns an exit code of 1 if the
* user answers Y or y; otherwise it returns 0. The
* error code could be tested in a batch file.
*/

#include <conio.h>
#include <stdlib.h>

void main( void )
{
int ch;

_cputs( "Yes or no? " );
ch = _getch();
_cputs( "\r\n" );
if( toupper( ch ) == 'Y' )
exit( 1 );
else
exit( 0 );
}

canany1tellme 2005-01-01
  • 打赏
  • 举报
回复
没什么意思,一般来说exit的参数是进程的返回码,一般是错误码,0表示没有错误,不过你可以自己定义

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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