EXIT_FAILURE vs exit(1)?

后端 未结 5 1648
旧时难觅i
旧时难觅i 2021-01-30 01:16

What\'s the difference? Which is preferred, or when should I use each one respectively?

5条回答
  •  自闭症患者
    2021-01-30 02:16

    There are conventions for what sorts of status values certain programs should return. The most common convention is simply 0 for success and 1 for failure. Programs that perform comparison use a different convention: they use status 1 to indicate a mismatch, and status 2 to indicate an inability to compare. Your program should follow an existing convention if an existing convention makes sense for it.

    Some non-POSIX systems use different conventions for exit status values. For greater portability, you can use the macros EXIT_SUCCESS and EXIT_FAILURE for the conventional status value for success and failure, respectively. They are declared in the file stdlib.h.

提交回复
热议问题