[TUHS] C question for the historians

Ralph Corderoy ralph at inputplus.co.uk
Thu Nov 9 04:14:20 AEST 2017

Hi art,

> >     if (flags & DLADM_OPT_PERSIST) {
> >     if ((flags & DLADM_OPT_PERSIST) == 0) {
> To me, anything non-zero is "true" so the first is perfectly
> acceptable.

It's not what acceptable that matters, but what's idiomatic as that is
instantly familiar to other readers and lets them read code without
being jolted out of concentrating on the important stuff by wondering
why the expression isn't idiomatic, was something else meant instead,
and does it mean the author has dodgy practices.
`if (w & MASK)' is idiomatic.

> The original assertion in the discussion was that the following is not
> "right" because of the mixing of bitwise and boolean.
> > if ((flags & DLADM_OPT_PERSIST) && (link_flags & DLMGMT_PERSIST)) {

What's the alternative?  As the Eskimo C FAQ points out, if you think

    if ((w & MASK) != FALSE)

is better then why stop there?  Why not

    if (((w & MASK) != FALSE) == TRUE)

Cheers, Ralph.

More information about the TUHS mailing list