Return Code on failure. Positive or negative?

前端 未结 6 1105
野的像风
野的像风 2021-01-04 18:14

a C-programm can fail to execute under special circumstances in Linux. Example: You allocate some space and the OS denies it.

char *buffer = (char *) malloc         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 18:50

    The exit code on UNIX/Linux from a process, the return statement in main() or a call to exit(), is unsigned in the range 0 - 255.

    From a function it can be any type you want it to be. Many library functions return -1 on error.

    However that is not always possible, particularly functions that normally return a pointer. By convention those functions return NULL on error, examples are fopen() and malloc().

    These return codes only indicate that an error has occurred, not what the error is, usually (on error) the global errno is also set to a positive error code giving further information. See man errno

提交回复
热议问题