cvs commit: src/sys/vm vm_mmap.c

Garance A Drosihn drosih at rpi.edu
Sun Jun 22 18:29:22 PDT 2003


At 7:43 PM +0200 6/21/03, Poul-Henning Kamp wrote:
>  >>   Log:
>  >>   Use a do {...} while (0); and a couple of breaks to reduce
>  >>   the level of indentation a bit.
>>>  
>>>    Revision  Changes    Path
>>>    1.161     +80 -78    src/sys/vm/vm_mmap.c
>  >> http://cvsweb.FreeBSD.org/src/sys/vm/vm_mmap.c.diff?r1=1.160&r2=1.161
>>
>>I find this change truly repulsive and gratuitous.
>
>It is a precusor to moving devices out of vnodes.  In order to
>get the patch which _does_ something to be manageable, I will
>sort out some minor issues first, this is one of them.
>
>If your complaint is about the use of do { ... break; ... break; }
>while (0); then launch an campaign to have it banned in style 9.
>
>IMO it is superior to goto, and ever deepening if-else constructs.

For this specific example, I don't see that it really buys you
all that much.  However, I would say that there are times that
the 'do { ... break; ... break; } while (0);'
strategy can be much easier to read than ever-deepening if-else's.
I would not be happy to see it banned in style(9).

When I use it, I do tend to put a comment on the either the
first or the file line, eg:
	do {		/* just a target for 'break's */
	} while (0);	/* just a target for 'break's */

This is just my own opinion, of course.  I'm not going to get all
wild-eyed and pound the table over it.  The other tactic I use is:
	if (...) {
		if (other)
			goto skipstuff;
  		if (yetmore)
			goto skipstuff;
		...stuff...
	skipstuff:
		alwaydo()
	}
which works about the same when it comes to indent-levels.

-- 
Garance Alistair Drosehn            =   gad at gilead.netel.rpi.edu
Senior Systems Programmer           or  gad at freebsd.org
Rensselaer Polytechnic Institute    or  drosih at rpi.edu


More information about the cvs-src mailing list