The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: ralph@inputplus.co.uk (Ralph Corderoy)
Subject: [TUHS] C question for the historians
Date: Wed, 08 Nov 2017 18:14:20 +0000	[thread overview]
Message-ID: <20171108181420.517711F949@orac.inputplus.co.uk> (raw)
In-Reply-To: <bd0bd6ba-ef3d-768f-6ae1-89240dff165c@kilonet.net>

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.
https://plus.google.com/+RalphCorderoy


  parent reply	other threads:[~2017-11-08 18:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 16:17 Arthur Krewat
2017-11-08 16:27 ` Warner Losh
2017-11-09 10:17   ` Michael Kjörling
2017-11-08 18:14 ` Ralph Corderoy [this message]
2017-11-08 18:34   ` Arthur Krewat
2017-11-08 19:05   ` Larry McVoy
2017-11-08 20:13     ` ron minnich
2017-11-08 20:23       ` Larry McVoy
2017-11-08 20:32         ` Ron Natalie
2017-11-08 20:39       ` Warner Losh
2017-11-08 20:41       ` Chet Ramey
2017-11-09  1:22         ` Ralph Corderoy
2017-11-09  1:41           ` Chet Ramey
2017-11-09  1:49             ` Arthur Krewat
2017-11-08 20:43       ` Bakul Shah
2017-11-08 20:55       ` Steve Nickolas
2017-11-08 20:36     ` Warner Losh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171108181420.517711F949@orac.inputplus.co.uk \
    --to=ralph@inputplus.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).