Date: Mon, 31 Dec 2001 13:38:53 -0800 (PST) From: Julian Elischer <julian@elischer.org> To: John Baldwin <jhb@FreeBSD.org> Cc: Poul-Henning Kamp <phk@critter.freebsd.dk>, cvs-all@FreeBSD.org, cvs-committers@FreeBSD.org, Julian Elischer <julian@FreeBSD.org>, Greg Lehey <grog@FreeBSD.org> Subject: Re: cvs commit: src/share/man/man3 queue.3 Message-ID: <Pine.BSF.4.21.0112311328270.94344-100000@InterJet.elischer.org> In-Reply-To: <XFMail.011231123912.jhb@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
There is code depending on this all over the place (not just in FreeBSD) but it's not documented.. better to document it than to just allow it to be a guess. On Mon, 31 Dec 2001, John Baldwin wrote: > > On 30-Dec-01 Poul-Henning Kamp wrote: > > In message <20011230094936.K90696@monorchid.lemis.com>, Greg Lehey writes: > >>On Saturday, 29 December 2001 at 8:55:05 +0100, Poul-Henning Kamp wrote: > >>> In message <200112282200.fBSM0Rw61760@freefall.freebsd.org>, Julian > >>> Elischer wr > >>> ites: > >>>> julian 2001/12/28 14:00:27 PST > >>>> > >>>> Modified files: > >>>> share/man/man3 queue.3 > >>>> Log: > >>>> Document some behaviour I'm depending on. > >>>> (TAILQ_FOREACH leaves the variable NULL if there were no more to do) > >>> > >>> I don't like this. > >> > >>Do you have a reason for not liking it? > > > > Yes, I don't like statements with weird sideeffects. If julian > > wants the sideeffect, he should not use a _FOREACH() macro to hide > > the internals of the loop. Most looping constructs in C and in FreeBSD have a correct completion method. It would be more surprising to me if it DIDN'T have one than if it did. In this case, I dispute that this is just a side effect. It is an exit condition. > > > > _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 */ } > > You could work around this via a goto instead I suppose: > > TAILQ_FOREACH(p, &list, p_next) > if (some_test_on(p)) > goto found; > goto not_found > found: > /* Do something */ > not_found: > > But that's uglier IMO. Definitly. It is ALWAYS possible to do it with more complicated constructs, but "why?". > > -- > > John Baldwin <jhb@FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/ > "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0112311328270.94344-100000>