[TUHS] C question for the historians

Michael Kjörling michael at kjorling.se
Thu Nov 9 20:17:54 AEST 2017

On 8 Nov 2017 09:27 -0700, from imp at bsdimp.com (Warner Losh):
> Or do the Linux-school and go with
>     if (!!(flags & DLADM_OPT_PERSIST)) {
> to really confuse things...

That smells like a Javascript influence to me, where

    if (!!x)

 or z = !!x;

is _more or less_ idiomatic for

    if (x == true)

 or z = x == true ? true : false;

(mind the difference between _assignment_ = and _equality_ == and
_actually equals_ ===)

or what in another language could be written as something largely
similar to a simple

    if (x)

if so desired.

Simply, !!x coerces x from whatever it is to a boolean, based on the
_truthiness_ of x. Where _truthiness_ is another of those lovely
Javascript concepts.

This, of course, is partly because Javascript (even more so than, say,
C) lacks _any_ sane idea of types. Its type system is more similar to
that of BCPL or PHP than even C, in that not only do you get to keep
the pieces if things break (assuming that you're lucky enough to
_know_ that things broke), but also that anything goes anywhere. That
variable which held a boolean a moment ago? Sure, go right ahead and
put an object or an array or a string in it. The next line of code can
replace it with a floating-point value or single character no problem,
and then you can have a conditional based on whether or not the latter
has sufficient truthiness.

(People who work with quantum computers must love that language.)

Michael Kjörling • https://michael.kjorling.semichael at kjorling.se
                 “People who think they know everything really annoy
                 those of us who know we don’t.” (Bjarne Stroustrup)

More information about the TUHS mailing list