lkml.org 
[lkml]   [2015]   [Apr]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Staging: rtl8188eu: Remove zero testing pointer typed value
On Fri, Apr 03, 2015 at 10:01:10AM -0700, Joe Perches wrote:
> On Fri, 2015-04-03 at 19:51 +0300, Dan Carpenter wrote:
> > Also strcmp() and similar should always be done as == 0, < 0 or != 0
> > because that is the idiom:
>
> Less true.
>
> When testing for equality, !strcmp is very common.
>
> There are ~2500 uses of !strcmp in the kernel tree vs
> ~1500 uses of strcmp() == or !=

Bugs with reversed strcmp() tests are almost always caught in testing so
it's not an issue. But == 0 is more correct. ;)

1) It's more clear when read in English. "if not strcmp then" or
"if strcmp NOT EQUAL zero". In the second one I've emphasized the
NOT EQUAL because the strings are not eqaul.

2) Also if works for the other compares too.

if (strcmp(x, y) < 0) <-- means x is less than y.
if (strcmp(x, y) == 0) <-- means x == y.

regards,
dan carpenter


\
 
 \ /
  Last update: 2015-04-03 23:41    [W:0.065 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site