当 assert() 失败时,程序退出代码是什么? [英] When assert() fails, what is the program exit code?

查看:45
本文介绍了当 assert() 失败时,程序退出代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

assert() 调用失败,使用的退出代码是什么,记录在哪里?

When an assert() call fails, what is the exit code used, and where is it documented?

推荐答案

C99(在 C11 中未更改)标准规定 assert 调用 abortabort 内容说明了有关返回代码的内容:

The C99 (unchanged in C11) standard states that assert calls abort and the abort stuff states this about the return code:

状态不成功终止的实现定义形式通过函数调用raise(SIGABRT)返回给宿主环境.

An implementation-defined form of the status unsuccessful termination is returned to the host environment by means of the function call raise(SIGABRT).

它记录在 C99 标准的第 7.2.1.1 节(断言)和 7.20.4.1(中止)此处.

It's documented in section 7.2.1.1 (assert) and 7.20.4.1 (abort) of the C99 standard here.

许多 UNIX 系统将返回 128 加上信号编号(SIGABRT 是信号编号 6),因此您可能会得到 134.无论您得到什么,都应该由 C 实现记录.

Many UNIX systems will return 128 plus the signal number (SIGABRT is signal number 6) so you may get 134. Whatever you get, it should be documented by the C implementation.

例如,请参阅此处 用于 gcc.尽管它对返回到调用环境的内容保持沉默.从特定部分这里:

For example, see here for gcc. Although it's quite silent on what gets returned to the calling environment. From the specific sections here:

某些选择是由库和操作系统(或为独立环境编译时的其他环境)做出的;有关详细信息,请参阅他们的文档.

Some choices are made by the library and operating system (or other environment when compiling for a freestanding environment); refer to their documentation for details.

这里:

这些点的大部分行为都依赖于 C 库的实现,而不是由 GCC 本身定义的.

The behavior of most of these points are dependent on the implementation of the C library, and are not defined by GCC itself.

glibc 文件也是如此 此处 程序终止(特别是退出状态位).它提到了惯例,但没有确定的规则.

So is the glibc doco here on program termination (specifically the exit status bit). It mentions conventions but no firm rules.

这篇关于当 assert() 失败时,程序退出代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆