C++: How can I return a negative value in main.cpp

前端 未结 3 1722
鱼传尺愫
鱼传尺愫 2020-12-30 00:29

As an assignment in school, we have to write a C++ program and returns different error codes in the main.

The problem is that we have to return -2

3条回答
  •  生来不讨喜
    2020-12-30 01:29

    Unix, and linux are limited to 8 bit return codes, -2 is 0xfe. Which your shell will understand to be 254 when you echo $?

    You're expected to give a return code between 0 and 255.

    http://en.wikipedia.org/wiki/Exit_status

    on POSIX-compatible exit statuses are restricted to values 0-255, the range of an unsigned 8-bit integer.

提交回复
热议问题