Re: [PATCH] NMI trigger switch support for debugging

From: Mikael Pettersson
Date: Wed May 26 2004 - 16:26:39 EST


Paul Jackson writes:
> Mikael Pettersson, replying to AKIYAMA Nobuyuki:
> > > + if (!old_state == !unknown_nmi_panic)
> > > + return 0;
> >
> > This conditional looks terribly obscure.
>
> Would the following variant seem clearer:
>
> if (!!unknown_nmi_panic == !!old_state)
> return 0;
>
> Odd, I know. For those of us familiar with the '!!' idiom, which
> converts any value to its binary logical equivalent 0 (if zero) or
> 1 (otherwise), this reads as:
>
> if (the logical value of unknown_nmi_panic is unchanged)
> return 0;

The !! idiom has the advantage of making it crystal clear
that the author is comparing boolean-normalised values.
The code I commented on was unusual enough that I couldn't
ignore the possibility of a bug.

In this case, I'd prefer the !! idiom, or moving the test into
the two state-changing code snippets below it.

/Mikael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/