<分区>
要么我没有搜索好,要么这个问题很明显。
在c
中,main函数返回你想要的。但是由于Posix给出了例子,0表示成功,其他值表示失败(Linux中大多为正值)。
基于这个假设,我看到了一个实践,其中代码中的所有其他函数都具有相同的行为。
- 优点:
- 实用,因为您可以直接将调用结果作为主函数的结果返回
- 缺点:
- 0 为 OK,1 为 KO。
我确定它不好,但我这里有 200 万行基于此。
这很常见吗?它有名字吗?
<分区>
要么我没有搜索好,要么这个问题很明显。
在c
中,main函数返回你想要的。但是由于Posix给出了例子,0表示成功,其他值表示失败(Linux中大多为正值)。
基于这个假设,我看到了一个实践,其中代码中的所有其他函数都具有相同的行为。
我确定它不好,但我这里有 200 万行基于此。
这很常见吗?它有名字吗?
最佳答案
成功返回 0
很常见。这种行为没有具体名称。
这是 C 标准所说的:
7.22.4.4 The exit function
...
2. Theexit
function causes normal program termination to occur.
...
5. Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned. Otherwise the status returned is implementation-defined.
关于c - c函数在有效行为后返回零是标准的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53813429/