c - c函数在有效行为后返回零是标准的吗?

标签 c function

<分区>

要么我没有搜索好,要么这个问题很明显。

c中,main函数返回你想要的。但是由于Posix给出了例子,0表示成功,其他值表示失败(Linux中大多为正值)。

基于这个假设,我看到了一个实践,其中代码中的所有其他函数都具有相同的行为。

  • 优点:
    • 实用,因为您可以直接将调用结果作为主函数的结果返回
  • 缺点:
    • 0 为 OK,1 为 KO。

我确定它不好,但我这里有 200 万行基于此。

这很常见吗?它有名字吗?

最佳答案

成功返回 0 很常见。这种行为没有具体名称。

这是 C 标准所说的:

7.22.4.4 The exit function
...
2. The exit 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/

相关文章:

c - 在一个函数中删除所有二叉搜索树

c - C 风格命名约定的要点

c - 是否有任何 C 库为 GNU/Linux 实现 C11 线程?

c - 我如何从源代码静态构建 GDB?

r - 了解 R 中的 switch() 函数?

python - 在 Python 中返回外部函数错误

c - 如何为 `system()` 调用的命令提供参数?

javascript - 为什么 JavaScript 中的 function.apply.length 是 2?

javascript - 代码输出一个数字而不是未定义的?

c - 有没有办法将没有显式命名类型的结构作为参数传递给函数?