EXIT_FAILURE vs exit(1)?

后端 未结 5 1580
旧时难觅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 01:56

    For truly portable code, EXIT_FAILURE is preferred. The C standard only defines meaning for three values: EXIT_FAILURE, 0, and EXIT_SUCCESS (with 0 and EXIT_SUCCESS essentially synonymous).

    From a practical viewpoint, most typical systems accept other values as well. If memory serves, Linux will let you return any 8-bit value, and Windows 16-bit values. Unless you honestly might care about porting to an IBM mainframe, VMS, etc., chances are you don't care about most of the systems that won't support at least 8-bit return values.

提交回复
热议问题