Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How bad is it to abandon THE rule in C (aka: return 0 on success)?

Tags:

c

in a current project I dared to do away with the old 0 rule, i.e. returning 0 on success of a function. How is this seen in the community? The logic that I am imposing on the code (and therefore on the co-workers and all subsequent maintenance programmers) is:

.>0: for any kind of success/fulfillment, that is, a positive outcome

==0: for signalling no progress or busy or unfinished, which is zero information about the outcome

<0: for any kind of error/infeasibility, that is, a negative outcome

Sitting in between a lot of hardware units with unpredictable response times in a realtime system, many of the functions need to convey exactly this ternary logic so I decided it being legitimate to throw the minimalistic standard return logic away, at the cost of a few WTF's on the programmers side.

Opininons?

PS: on a side note, the Roman empire collapsed because the Romans with their number system lacking the 0, never knew when their C functions succeeded!

like image 761
slartibartfast Avatar asked Nov 28 '22 03:11

slartibartfast


2 Answers

"Your program should follow an existing convention if an existing convention makes sense for it."

Source: The GNU C Library

like image 137
Ian Bishop Avatar answered Jan 21 '23 12:01

Ian Bishop


By deviating from such a widely known convention, you are creating a high level of technical debt. Every single programmer that works on the code will have to ask the same questions, every consumer of a function will need to be aware of the deviation from the standard.

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

like image 24
Fenton Avatar answered Jan 21 '23 12:01

Fenton