From owner-cvs-all Wed Jan 2 0:41:16 2002 Delivered-To: cvs-all@freebsd.org Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14]) by hub.freebsd.org (Postfix) with ESMTP id F08C837B41B; Wed, 2 Jan 2002 00:41:07 -0800 (PST) Received: from beagle (beagle [193.175.132.100]) by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id g028f0h00429; Wed, 2 Jan 2002 09:41:03 +0100 (MET) Date: Wed, 2 Jan 2002 09:41:00 +0100 (CET) From: Harti Brandt To: Marcel Moolenaar Cc: cvs-all@FreeBSD.ORG, Subject: Re: cvs commit: src/share/man/man3 queue.3 In-Reply-To: <20011231190126.A755@dhcp01.pn.xcllnt.net> Message-ID: <20020102093537.X1528-100000@beagle.fokus.gmd.de> 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: MM>On Mon, Dec 31, 2001 at 05:14:08PM -0800, Julian Elischer wrote: MM>> MM>> > I'd consider this a misuse of _FOREACH, because the something that's MM>> > being done is definitely not done for each p. Even some_test_on() is MM>> > not performed on each p. I'm with phk here. MM>> > MM>> > Note that if it's simply too easy to use _FOREACH in these cases, we MM>> > may want to consider creating a more suitable abstraction, like: MM>> > MM>> > TAILQ_UNTIL(p, &list, p_next) MM>> > some_test_on(p); MM>> > if (p == 0) MM>> > return ENOTFOUND; MM>> > /* do something */ MM>> > return 0; MM>> > MM>> > Just a thought. MM>> MM>> So you think that the final value of p should be undefined, MM>> and there is no built in way to see if there were any elements in the MM>> list at all or whether we completed the list? MM> MM>Theoretically speaking, yes. MM> MM>> I'm just documenting what the code does, and how people have used it. MM> MM>I understand that and didn't really object to that. MM> MM>> if you think that phk is correct we should add an example to the man page MM>> showing: MM>> MM>> MM>> TAILQ_FOREACH(p, &list, p_next) MM>> if (some_test_on(p)) MM>> goto fred; MM>> goto jim; MM>> fred: print ("we got one"); MM>> jim: MM> MM>What's wrong with the following if _FOREACH is preferred: MM> MM> TAILQ_FOREACH(p, &list, p_next) { MM> if (some_test_on(p)) { MM> /* Do something */ MM> break; /* optional */ MM> } MM> } This makes things harder to read if /* Do something */ is longer than a screen. Well, I think, that relying on the pointer beeing NULL if running to the end of the list just perfectly mirrors the usual C-idiom: for (i = 0; i < n; i++) if (test(i)) break; if (i == n) ... The TAILQ_UNTIL(...) would even more obscure things... harti -- harti brandt, http://www.fokus.gmd.de/research/cc/cats/employees/hartmut.brandt/private brandt@fokus.gmd.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message