[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wiwhMFo6GFUAg3CZJMix4TJo59NBaSDciQxW23RHR8Zbg@mail.gmail.com>
Date: Sun, 10 Nov 2019 14:35:13 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Joe Perches <joe@...ches.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, Jiri Slaby <jslaby@...e.cz>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"the arch/x86 maintainers" <x86@...nel.org>
Subject: Re: [GIT pull] core/urgent for v5.4-rc7
On Sun, Nov 10, 2019 at 2:01 PM Joe Perches <joe@...ches.com> wrote:
>
> trivia:
>
> This idiom '!!(logical test)' is odd and redundant.
> Logical test result is already 0 or 1, no !! is unnecessary.
You are of course correct.
I have to say, I personally have always disliked the idiomatic C "!!"
pattern. I don't think it reads well, although that's probably "C
cultural" - once you are used to the pattern, you don't think of it as
anything else.
Personally, I prefer "x != 0" over "!!x" since it reads much better to
a human, and is equally legible whether you're used to the !! pattern
or not.
C is not perl, the Obfuscated C contest not-withstanding.
And since modern C has bool, if you really want to use a cast-to-bool
instead of "x != 0", I think doing exactly that is preferable to "!!".
So I think both "x != 0" and "(bool)x" are preferable to "!!x", and
would also have made it obvious how odd and redundant the test was in
this case.
But "!!x" is shorter, of course. And it you learnt C with that pattern
it looks obvious.
Linus
Powered by blists - more mailing lists