C: exit的值

Stella981
• 阅读 440

运行node的process.exit时候发现了以前忽视的一个问题:

$ node
> process.exit(-1)

$ echo $?
255

我希望exit的值是-1,结果成了255。

===

http://stackoverflow.com/questions/12512177/exit-status-of-a-program 给出的解释:

Program return values mean different things on different operating systems. On Unix-y systems, only values 0-255 are valid (1 unsigned byte). Note this means negative values are not allowed, and may be the cause of your IDE problems. FreeBSD introduced a load of specific meanings in sysexits.h, and while this certainly exists on Linux distributions I've used, the only real universally accepted one is 0 for success and non-0 for failure. As Pete Becker points out, EXIT_SUCCESS and EXIT_FAILURE are standard defined macros (0 and 1 respectively on Unix-y platforms, but implementation defined).

On windows, you get a 32 bit signed integer (negatives are allowed, don't know if they mean anything). Again, 0 is success, and other values mean various things. Like echo $?, you can use echo %errorlevel% to see the last program's exit code in the console.

Also note that my N3337 (draft very close to C++11 standard) says at section 3.6.1 paragraph 5:

If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;

===

C语言示例:

示例1

#include <stdio.h>

int 
main() 
{

    return 0;

}

退出码为0。

示例2

#include <stdio.h>

int 
main() 
{

    return -1;

}

退出码为255.

示例3

#include <stdio.h>
#include <stdlib.h>

int 
main() 
{

    exit(-1);

}

退出码为255.

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Python进阶者 Python进阶者
2年前
一篇文章带你了解CSS 文本样式
大家好,我是IT共享者,人称皮皮。这篇文章我们来讲讲CSS的文本样式。一、文本颜色Color颜色属性被用来设置文字的颜色。颜色是通过CSS最经常的指定:十六进制值如"#FF0000"。一个RGB值"RGB(255,0,0)"。颜色的名称如"红"。一个网页的文本颜色是指在主体内的选择:
Wesley13 Wesley13
2年前
java 类型转换的原理
最近在看JDK的源码,在看源码的时候看到了0xff这么个东东,从这里引出了类型转换。因此在此记录下。在写原理之前先看几个例子。byteb1;intab;然后打印a得出的结果是1.intb1;bytea(byte)b;打印a得出来的是1。inta255;byteb(byte)255;打印b得出的结果也是1;而把这个强制转出
Stella981 Stella981
2年前
MapReduce应用
1、MapReduce实现矩阵相乘一.准备数据!/bin/bashif  $ ne 3 then  echo "there must be 3 arguments to generate the two matries file!"  exit 1
Wesley13 Wesley13
2年前
JAVA拦截器,JAVA返回结果跨域问题解决
遇到的问题:通过拦截器做权限控制,没有权限时返回了json值,结果前端请求时提示跨域了备注:我的前端站点和后端站点不是一个地址报错1:AccesstoXMLHttpRequestat'http://localhost:8089/appcicd/appinfo/getappinfos'fromorigi
Stella981 Stella981
2年前
Laravel 控制器的request
publicfunctionrequest1(Request$request){//取值$nameRequest::input('name');//是否有值if($requesthas('name')){echo$requestinput('name');}$res
Stella981 Stella981
2年前
PHP接收前端传值各种情况整理
<h1PHP接收前端传值各种情况整理</h1<h2服务端代码:</h2header('AccessControlAllowOrigin:');var_dump($_POST);exit;<h2情况</h2<h31)传null</h3$.pos
Wesley13 Wesley13
2年前
IOS编译过程出现过的错误汇总
1.sending'MainViewConroller\const\_strong'toparameterofincompatibletype'<NSFileManagerDelegate错误解决方案:http://stackoverflow.com/questions/24248825/gettingawa
Wesley13 Wesley13
2年前
mysql select将多个字段横向合拼到一个字段
表模式:CREATE TABLE tbl_user (  id int(11) NOT NULL AUTO_INCREMENT,  name varchar(255) DEFAULT NULL,  age int(11) DEFAULT NULL,  PRIMARY KEY (id)
Wesley13 Wesley13
2年前
oracle小数点前零丢失的问题
1.问题起源 oracle数据库字段值为小于1的小数时,使用char类型处理,会丢失小数点前面的0 例如0.35就变成了.35 2.解决办法:(1)用to\_char函数格式化数字显示 select    to\_char(0.338,'fm9999999990.00')fromdual; 结果:0.34