From owner-cvs-all Fri Dec 27 11:49:46 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 41E9137B401; Fri, 27 Dec 2002 11:49:44 -0800 (PST) Received: from mta6.snfc21.pbi.net (mta6.snfc21.pbi.net [206.13.28.240]) by mx1.FreeBSD.org (Postfix) with ESMTP id E7B7743EC2; Fri, 27 Dec 2002 11:49:43 -0800 (PST) (envelope-from hsu@FreeBSD.org) Received: from FreeBSD.org ([63.193.112.125]) by mta6.snfc21.pbi.net (iPlanet Messaging Server 5.1 HotFix 1.6 (built Oct 18 2002)) with ESMTP id <0H7S0085XN2VDE@mta6.snfc21.pbi.net>; Fri, 27 Dec 2002 11:49:43 -0800 (PST) Date: Fri, 27 Dec 2002 11:50:40 -0800 From: Jeffrey Hsu Subject: Re: cvs commit: src/sys/kern uipc_usrreq.c In-reply-to: Message from Matthew Dillon "of Fri, 27 Dec 2002 10:55:44 PST." <200212271855.gBRItiIC057945@apollo.backplane.com> To: Matthew Dillon Cc: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG Message-id: <0H7S0085YN2VDE@mta6.snfc21.pbi.net> MIME-version: 1.0 X-Mailer: exmh version 2.5 07/13/2001 with nmh-1.0.4 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > 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