The mix of conventions is a bit counter-intuitive, but the conventions are:
Program success = 0
Program other status = non zero
Within a program false = 0
Within a program true = non zero
Strict bool false = 0
Strict bool true = 1
Quote:
Originally Posted by tadeas
if I want a function to do some computations on parameters passed by reference and return success status. Should it return 1 (true) for success, or should it return 0 for success - like any Unix program does?
Is there any convention for this?
|
Unfortunately, for function success/failure there is no well recognized convention.
How many different success values might you need? How many different failure values might you need? Someone apparently decided that for Unix program exit status only one success value was needed and multiple non success values.
If you only need one failure value, I find code a lot more readable if false is failure where tested by the calling function, so I prefer 0 as a fail code.