From owner-cvs-all Mon Dec 31 17:20:13 2001 Delivered-To: cvs-all@freebsd.org Received: from rwcrmhc53.attbi.com (rwcrmhc53.attbi.com [204.127.198.39]) by hub.freebsd.org (Postfix) with ESMTP id 6E94C37B423; Mon, 31 Dec 2001 17:20:07 -0800 (PST) Received: from InterJet.elischer.org ([12.232.206.8]) by rwcrmhc53.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020101012006.OSRC20122.rwcrmhc53.attbi.com@InterJet.elischer.org>; Tue, 1 Jan 2002 01:20:06 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id RAA11208; Mon, 31 Dec 2001 17:14:09 -0800 (PST) Date: Mon, 31 Dec 2001 17:14:08 -0800 (PST) From: Julian Elischer To: Marcel Moolenaar Cc: John Baldwin , Poul-Henning Kamp , cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Julian Elischer , Greg Lehey Subject: Re: cvs commit: src/share/man/man3 queue.3 In-Reply-To: <20011231165233.A408@dhcp01.pn.xcllnt.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 On Mon, 31 Dec 2001, Marcel Moolenaar wrote: > On Mon, Dec 31, 2001 at 01:38:53PM -0800, Julian Elischer wrote: > > > > > > > > _FOREACH() is for the plain & simple traversal of a queue(3) stucture, > > > > anything more should explicitly state intent. > > > > > > I would agree except for code like this: > > > > > > TAILQ_FOREACH(p, &list, p_next) > > > if (some_test_on(p)) > > > break; > > > if (p != NULL) { > > > /* Found one, now do something. */ > > > } > > > > This is the case I'm using it for. > > except I'm doing: > > TAILQ_FOREACH(p, &list, p_next) > > if (some_test_on(p)) > > break; > > if (p != NULL) { > > /* Found it, now do something. */ > > } > > lots of code that MAY clear p > > if (p == NULL) { > > /* didn't find it, or it was disqualified */ > > } > > I'd consider this a misuse of _FOREACH, because the something that's > being done is definitely not done for each p. Even some_test_on() is > not performed on each p. I'm with phk here. > > Note that if it's simply too easy to use _FOREACH in these cases, we > may want to consider creating a more suitable abstraction, like: > > TAILQ_UNTIL(p, &list, p_next) > some_test_on(p); > if (p == 0) > return ENOTFOUND; > /* do something */ > return 0; > > Just a thought. So you think that the final value of p should be undefined, and there is no built in way to see if there were any elements in the list at all or whether we completed the list? just checking.. (sounds like a good excuse for adding more complicated code to me) I'm just documenting what the code does, and how people have used it. if you think that phk is correct we should add an example to the man page showing: TAILQ_FOREACH(p, &list, p_next) if (some_test_on(p)) goto fred; goto jim; fred: print ("we got one"); jim: personally I thik that is more obscure than: TAILQ_FOREACH(p, &list, p_next) if (some_test_on(p)) break; if (p) { print ("we got one"); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message