From owner-freebsd-arch Thu Aug 16 8:17: 6 2001 Delivered-To: freebsd-arch@freebsd.org Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by hub.freebsd.org (Postfix) with ESMTP id B15BA37B401 for ; Thu, 16 Aug 2001 08:17:02 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id BAA09325; Fri, 17 Aug 2001 01:16:39 +1000 Date: Fri, 17 Aug 2001 01:16:37 +1000 (EST) From: Bruce Evans X-X-Sender: To: Mark Murray Cc: Subject: Re: Style 9 nitpicking question In-Reply-To: <200108161010.f7GAAsK68419@grimreaper.grondar.za> Message-ID: <20010817005031.S29341-100000@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, 16 Aug 2001, Mark Murray wrote: > A piece of style(9) says: > > > > static void > usage() > { > /* Insert an empty line if the function has no local variables. */ > > Use printf(3), not fputs/puts/putchar/whatever; it's faster and usually > cleaner, not to mention avoiding stupid bugs. > > [ snip ] > > "usage: f [-aDde] [-b b_arg] [-m m_arg] req1 req2 [opt1 [opt2]]\n" > "usage: f [-a | -b] [-c [-dEe] [-n number]]\n" > > (void)fprintf(stderr, "usage: f [-ab]\n"); > exit(EX_USAGE); > } > > > > Questions: > > 1) That "(void)" is useless by any metric that I am able to determine > (WARNS=2, BDECFLAGS etc), and gets in the way of linting. Is there > any reason to continue to advocate its use by this example? There > is no other reference to "voiding-out" of return values. It by prevents warnings like the following from `lint -h': "snprintf returns a value which is sometimes ignored" "snprintf returns a value which is always ignored" This is the opposite of getting in the way of linting. > 2) Is this (fprintf(stderr, "...", ...); exit(n);) really better than > errx(1, "...", ...); ? Yes. The former is more portable, and prints the program name in the usual place (after "usage: "). > Any objections to changing the > > (void)fprintf(stderr, "usage: f [-ab]\n"); > exit(EX_USAGE); > > to > > errx(EX_USAGE, "usage: f [-ab]\n"); Yes :-). The second form here has the additional bug of printing the program name twice (perhaps different names if the binary is linked). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message