C: exit的值

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

1$ node 2> process.exit(-1) 3 4$ echo $? 5255

我希望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

1#include <stdio.h> 2 3int 4main() 5{ 6 7 return 0; 8 9}

退出码为0。

示例2

1#include <stdio.h> 2 3int 4main() 5{ 6 7 return -1; 8 9}

退出码为255.

示例3

1#include <stdio.h> 2#include <stdlib.h> 3 4int 5main() 6{ 7 8 exit(-1); 9 10}

退出码为255.

点赞
收藏

评论区

加载中...

相关推荐

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

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

java 类型转换的原理

最近在看JDK的源码,在看源码的时候看到了0xff这么个东东,从这里引出了类型转换。因此在此记录下。在写原理之前先看几个例子。byteb1;intab;然后打印a得出的结果是1.intb1;bytea(byte)b;打印a得出来的是1。inta255;byteb(byte)255;打印b得出的结果也是1;而把这个强制转出

MapReduce应用

1、MapReduce实现矩阵相乘一.准备数据!/bin/bashif  $ ne 3 then  echo "there must be 3 arguments to generate the two matries file!"  exit 1

JAVA拦截器,JAVA返回结果跨域问题解决

遇到的问题:通过拦截器做权限控制,没有权限时返回了json值,结果前端请求时提示跨域了备注:我的前端站点和后端站点不是一个地址报错1:AccesstoXMLHttpRequestat'http://localhost:8089/appcicd/appinfo/getappinfos'fromorigi

Laravel 控制器的request

publicfunctionrequest1(Request$request){//取值$nameRequest::input('name');//是否有值if($requesthas('name')){echo$requestinput('name');}$res