[webkit-dev] strcmp result checking

Maciej Stachowiak mjs at apple.com
Thu Dec 17 10:10:46 PST 2009

On Dec 17, 2009, at 9:24 AM, Simon Fraser wrote:

> On Dec 16, 2009, at 10:02 PM, Peter Kasting wrote:
>> On Wed, Dec 16, 2009 at 9:12 PM, Alexey Proskuryakov  
>> <ap at webkit.org> wrote:
>> As current style rules say that tests for zero/non-zero should all  
>> be done without equality comparisons. However, this rule can cause  
>> significant readability problems if blindly applied to strcmp: if (! 
>> strcmp(string, "foobar")) naturally reads as "does not equal".
>> I have always found !strcmp() to be more readable than the == 0  
>> form, rather than less.  I don't have a logical explanation for  
>> this, it just reads as "if strcmp didn't find differences" to me.
>> I definitely wish we'd be consistent in our usage whichever way  
>> people agree on.
> The better solution here would be to have an inline function strequal 
> () that returns a bool, and use that instead of strcmp() when  
> testing for equality.

Agreed. Both !strcmp(...) and strcmp(...) == 0 are potentially  
confusing, and we have it in our power to limit the potential  
confusion to only one place in the code.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20091217/c3adfe22/attachment.html>

More information about the webkit-dev mailing list