From owner-svn-src-head@FreeBSD.ORG Tue Dec 14 08:26:19 2010 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EEC601065A1F; Tue, 14 Dec 2010 08:26:18 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184]) by mx1.freebsd.org (Postfix) with ESMTP id 7D4B28FC1E; Tue, 14 Dec 2010 08:26:17 +0000 (UTC) Received: from c122-106-172-0.carlnfd1.nsw.optusnet.com.au (c122-106-172-0.carlnfd1.nsw.optusnet.com.au [122.106.172.0]) by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id oBE8QEf7010464 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 14 Dec 2010 19:26:15 +1100 Date: Tue, 14 Dec 2010 19:26:13 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Xin LI In-Reply-To: <201012140021.oBE0LZI9097999@svn.freebsd.org> Message-ID: <20101214183752.L870@besplex.bde.org> References: <201012140021.oBE0LZI9097999@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r216422 - head/usr.bin/printf X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Dec 2010 08:26:19 -0000 On Tue, 14 Dec 2010, Xin LI wrote: > Log: > Make use of EX_USAGE for usage(). Most uses of sysexits are styyle bugs. This one is no exception, since printf is not sendmail. > Modified: head/usr.bin/printf/printf.c > ============================================================================== > --- head/usr.bin/printf/printf.c Mon Dec 13 23:53:55 2010 (r216421) > +++ head/usr.bin/printf/printf.c Tue Dec 14 00:21:34 2010 (r216422) > @@ -115,14 +116,14 @@ main(int argc, char *argv[]) > case '?': > default: > usage(); > - return (1); > + /* NOTREACHED */ Most uses of NOTREACHED are style bugs. This one is no exception, since usage() obviously doesn't return. Even lint(1) can see this. It used to be necessary to declare usage() as __dead2 so that compilers see this, but now -funit-at-a-time is a default so this ugliness is no longer useful either (except if usage() in a separate file. exit(3) is in a separate file, but it is declared as __dead2. style(9) still has the bugs of saying to use sysexits and using EX_USAGE in its usage(). It has a bad recommendation for NOTREACHED too. It gives one example of using NOTREACHED. This is after one of its calls to usage(). This is a particularly bad example, since NOTREACHED is not needed there, and it is not used after the other example of usage() where it is equally [not] needed. style(9) doesn't use NOTREACHED after its calls to exit(), where it is almost equally [not] needed -- everyone knows that exit() doesn't return, and everyone should know that usage() doesn't return too. You fixed the style bug that printf(1)'s usage did return. Everyone knows that the err() family doesn't return, and of course style(9) doesn't use NOTREACHED after its examples of calls to err*() either. These examples show that style(9)'s recomendation that NOTREACHED should be used for [all] code that cannot be reached is so wrong that even style(9) knows not to follow it. style(9) still hasn't caught up with the early 1990's development of using __dead2 to give an active declaration of functions that don't return, so that the 1970-1980's method of using NOTREACHED can be avoided in most cases, in particular after exit(), err*() and usage(), except as an example of what not to do like one of calls to exit() (*). NOTREACHED remains useful for avoiding some lint and compiler lifetime analysis deficiencies, and for telling human readers that although the code is tangled this part of it really is not reached. Using it for code that is obviously not reached reduces its force in these cases. (*) Reading between the lines, I wilfully misinterpret this example of being a bad example of everthing it does: % Exits should be 0 on success, or according to the predefined values in % sysexits(3). % % exit(EX_OK); /* % * Avoid obvious comments such as % * "Exit 0 on success." % */ Things not to do that are done in this example include: - use EX_OK, not 0 on success - place comments to the right of the code and extend them across multiple lines for maximal waste of space - when changing code to use EX_OK (or anything, be sure to neglect to change the comments, so that the comments don't match the code). [Here this was originally just a bad example of an obvious comment. The code said exit(0) and the comment said 0 too. Now it doesn't say EX_OK, so it is not so obvious that this is an obvious comment (in fact, EX_OK does equal 0, but this is of no interest here).] This example could be further improved by adding an obvious NOTREACHED comment to it. style(9) still hasn't caught up with the late 1990's development of using EXIT_SUCCESS. This C90 macro for spelling 0 is about as popular as POSIX's STDIN_FILENO, but at least it is Standard, unlike EX_OK. Bruce