Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Dec 2002 11:50:40 -0800
From:      Jeffrey Hsu <hsu@FreeBSD.org>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/kern uipc_usrreq.c
Message-ID:  <0H7S0085YN2VDE@mta6.snfc21.pbi.net>
In-Reply-To: Message from Matthew Dillon <dillon@apollo.backplane.com> "of Fri, 27 Dec 2002 10:55:44 PST." <200212271855.gBRItiIC057945@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help

  > It will work

Yes, let's not forget this.  The old code didn't work.  And, the
question that was initially asked a basic C sequence point question
on whether the ternary operator worked with the pre-increment operator.

  > there really is no reason
  > to collapse the mess onto a single line

I can think of three reasons:

1.  Precedent

See netinet/tcp_seq.h:

/* Macro to increment a CC: skip 0 which has a special meaning */
#define CC_INC(c)       (++(c) == 0 ? ++(c) : (c))

2.  Readability

Compare the committed version

        if (unp->unp_ino == 0)
                unp->unp_ino = (++unp_ino == 0) ? ++unp_ino : unp_ino;
        sb->st_ino = unp->unp_ino;

with the broken out version

        if (unp->unp_ino == 0)
		if (++unp_ino == 0)
			unp->unp_ino = ++unp_ino;
		else
			unp->unp_ino = unp_ino;
        sb->st_ino = unp->unp_ino;

The second version obscures the assignment inside the control flow.
The similarity of the unp->unp_ino and unp_ino names makes
it hard for the naked eye to follow the multiple occurrences of
unp->unp_ino and unp_ino.

The committed version makes it clear the assignment to unp->unp_ino
is the primary intent of the body of the conditional.

3.  Brevity

The committed version is shorter.

							Jeffrey


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0H7S0085YN2VDE>