Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

c - When assert() fails, what is the program exit code?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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.

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.

And here:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...