From owner-svn-src-head@FreeBSD.ORG Sun Sep 16 21:22:06 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B4961106564A; Sun, 16 Sep 2012 21:22:06 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by mx1.freebsd.org (Postfix) with ESMTP id 3BD728FC0A; Sun, 16 Sep 2012 21:22:05 +0000 (UTC) Received: from c122-106-157-84.carlnfd1.nsw.optusnet.com.au (c122-106-157-84.carlnfd1.nsw.optusnet.com.au [122.106.157.84]) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q8GLLqsa026855 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 17 Sep 2012 07:21:53 +1000 Date: Mon, 17 Sep 2012 07:21:52 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Chris Rees In-Reply-To: Message-ID: <20120917063509.E3825@besplex.bde.org> References: <201209160755.q8G7tnMH036332@svn.freebsd.org> <20120916092818.GA81952@FreeBSD.org> <38FB39C4-7626-4D54-8197-E302BB9452D2@FreeBSD.org> <1347817284.1114.2.camel@revolution.hippie.lan> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Ian Lepore , Alexey Dokuchaev , src-committers@freebsd.org, svn-src-all@freebsd.org, David Chisnall , Andrew Turner , Bruce Evans , svn-src-head@freebsd.org Subject: Re: svn commit: r240549 - head/sys/arm/tegra 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: Sun, 16 Sep 2012 21:22:07 -0000 On Sun, 16 Sep 2012, Chris Rees wrote: > On 16 September 2012 18:41, Ian Lepore wrote: >> On Sun, 2012-09-16 at 18:30 +0100, Chris Rees wrote: >>> On 16 Sep 2012 16:19, "David Chisnall" wrote: >>>> >>>> On 16 Sep 2012, at 10:37, Chris Rees wrote: >>>> >>>>> Actually: >>>>> >>>>> for (;;) >>>>> ; >>>> >>>> This form will generate a compiler warning, because it looks like a >>> missing loop body. You can silence the warning by this form: >>>> >>>> for (;;) {} >>>> >>>> This makes it clear that you have an explicit body containing no >>> statements. This is forbidden by style(9) (it has excessive braces). >>> Please fix the style man page then, and make sure bde approves! >> >> One of the examples allows >> >> for (;;) >> stmt; >> >> Using "continue;" as the statement is consistant with that. So is using a null statement. Actually, the informal grammar in the example is buggy. In more formal grammars, the semicolon is part of a statement (unless the statement is compound). So the above should really be: for (;;) statement but that looks strange, and we know what the current version means. > Ok, so with approval from a docs/src guy I'd like to commit [1] to > update the style page to use continue; instead of a lone ; > ... > [1] http://www.bayofrum.net/~crees/patches/style-empty-loop.diff I don't like this. The style is whatever it was, not what you want it to be. However, I couldn't find a single example in /usr/src/*bin or libc that has an empty for loop. Normal code just doesn't do that. It would be better to remove the example of the empty loop in style(9), so that style(9) doesn't require any particular style for rarely-written code. Oops. The loop that you changed is not the above fully empty one, but one with control statements but no body. I couldn't find any like the above, and ones with control statements are too hard to grep for. The one that you changed is basically strlen(), and an example of existing (mal)practice was in the 4.4BSD version of strlen.c: % size_t % strlen(str) % const char *str; % { % const char *s; % % for (s = str; *s; ++s); % return(s - str); % } It doesn't even put the semicolon on a new line. strlen.c is now recomplicated, so it no longer provides a bad example. strlen() is also in K&R, with better style but a while loop: while (s[i] != '\0') i++; and of course the classic obfuscated idiom for strcpy is to do all the work in the control statment. This obfuscation is done fairly well in 4.4BSD again: for (; *to = *from; ++from, ++to); (why not *to++, etc?). I use a single semicolon for fully empty loops, but not put all of the work in the control statement for loops that do something, so that the never have an empty body. Adding 'continue /* nothing */' to the old BSD code wouldn't improve it. Its only good point is that it is concise, and this is defeated by redundant addiitons. Bruce