dev builds
themes manual
device status forums
mailing lists
IRC bugs
dev guide

Rockbox mail archive

Subject: Re: Read errors

Re: Read errors

From: Linus Nielsen Feltzing <>
Date: Thu, 13 Mar 2003 22:57:37 +0100

Mike Holden wrote:
> The other option, where the function does not return a boolean, is to make
> this more obvious in the if statement, so the above becomes "if (0 !=
> somefunction())", which makes the whole thing readable without hidden
> macros, and also makes it obvious to the reader of the code that
> somefunction() doesn't return a boolean, but an integer instead.

I'm not sure I agree. The fairly experienced C programmer knows what's
going on when he sees the "if(somefunction())" construct. He knows that
any nonzero value is a true value, boolean or not. He should also be
able to see from the context if a nonzero value is a success or not.

> That way
> it helps the reader who is not intimately familiar with the code, who may
> not know (without checking the source for it) that somefunction() returns
> 0 for success.

I don't see the difference. The if(func()) and the if(0 != func()) are
the same thing, and I prefer the first one, because there is less fluff.
The only issue is the "polarity" of the return code.

> Indeed. A well placed comment can make a world of difference, especially
> when unfamiliar with the code.

Absolutely. I often add comments to my code weeks after I have written
it, because then I see what parts I find hard to understand when I
examine my own code.

Received on 2003-03-13

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy