Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: Read errors
From: Linus Nielsen Feltzing (linus_at_haxx.se)
Date: 2003-03-13


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.

/Linus



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa