0 as a macro for successful result?

For more than 20 years, I’ve worked on/with many libraries and frameworks.
There are many oddities. Some were understandable, while others were clearly by wrong design.

However, for recent 10 years, many of such oddities were gone in many frameworks, libraries.
But still I see some.

Most recent one is to define 0 for meaning successful result and -1 or even 1 to mean failure.
As far as I remember, I saw such definition about 20 years ago in Microsoft header file.
For the recent 10 years, many of coding style became like this :

isSuccessful = DoSomething();
if( isSuccessful ) {


if a macro value for meaning success is 0 ( as a return value for DoSomething() ), writing code like above will fail.
So, it should be always like :

if( isSuccessful == T_SUCCESS) {


However, the naming the value as ‘isSuccessul’ is not really useful.
In 80’s and 90’s people tended to declare such variable name like ‘result”.

STATUS result = DoSomething();
if( result == T_SUCCESS) {


So, defining a successful value as 0 doesn’t match current style and even in 90’s style it is good only partially.
Actually even in 80’s and 90’s such values were set 1 or none-0. Failures were set 0, and -1 in some libraries.
Because 0 is implicitly evaluated as false and none-0s are true, it’s common sense to define some SUCCESS as 1 or non-0, and Failure as 0.

So, whether to follow 80’s and 90’s convention or contemporary convention, it’s very odd to define 0 as SUCCESS.

I wonder what people thought when they design it such a way.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: