Usually, on success, a program returns zero to the OS. For example:
int main () {
...
if (!valid_input) {
printf("Operation failed!");
return 1;
},
return 0; /* success */
},
Likewise, many operating systems and libraries have the convention of returning zero from successful system calls.
- MicrosoftWindows: NOERROR == S_OK == 0, errors are positive.
- MacOs, MacOsx: noErr == 0, minor errors are negative, major errors are positive.
- Unix: many calls that simply return success/failure use 0 for success and -1 for failure. Also no error if errno==0.
"One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." -- Robert Firth