lkml.org 
[lkml]   [2019]   [Jan]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] staging: vboxvideo: vbox_main: Remove unnecessary local variable
On Thu, Jan 10, 2019 at 05:00:24PM +0000, Sidong Yang wrote:
> I think you just point out that my code isn't obvious because the
> function returns negative error codes. I agree with you. But what if
> change my code like if(hgsmi_query_conf() != 0).
>

That's even worse! :P

You should do comparisons with zero when you are talking about zero
meaning the number zero. In this case, hgsmi_query_conf() returns "zezro
meaning success" not "zero meaning the number zero". How many bytes?
Zero. That is the number zero.

!= zero is a double negative, because NOT and ZERO are negatives. If
double negatives simplified the code we would add four of them instead
of just the one:

if ((((hgsmi_query_conf() != 0) != 0) != 0) != 0) {

See? Adding != 0 doesn't make it simpler...

The other place where != 0 is appropriate besides talking about the
number is when you're using a strcmp() function because it works like
this:

if (strcmp(a, b) < 0) { <-- means a < b
if (strcmp(a, b) == 0) { <-- means a == b
if (strcmp(a, b) != 0) { <-- means a != b

regards,
dan carpenter

\
 
 \ /
  Last update: 2019-01-10 20:44    [W:0.059 / U:0.296 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site