Subject: Re: Should PR 18434 be closed?
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/07/2003 06:30:32
> The reason why wi.c couldn't compile is that DELAY() macro on hpcmips
> was defined as a block like below and wi.c used DELAY() as a
> expression.

> from sys/arch/hpcmips/include/param.h
> #define DELAY(n)	{ register int N = cpuspeed * (n); while (--N > 0); }

> It is easy to modify DELAY() to:
> #define DELAY(n)	do {	\
> 		register int N = cpuspeed * (n); while (--N > 0);	\
> 	} while (/*CONSTCONT*/ 0)

That won't help; the result is still a statement, not an expression,
and thus can't be used in the repeat-clause of a for() loop.  (Well,
technically, it's only most of a statement.  But it's still not an

Wrapping a do-while around it as you did does help one problem, but
this isn't it.  (The problem it fixes is the "dangling else" problem:
if you write
	if (...) DELAY(10); else { ... }
then the orginal DELAY() will produce a syntax error because the ; ends
up being not the terminator that turns an expression into a statement,
but rather an empty statement which forces the if() statement to end
before the else-clause gets attached to it.  The do-while wrapper fixes
this by consuming the trailing semicolon.)

If you're willing to depend on gcc, you could write it as

#define DELAY(n) ({ register int N = cpuspeed * (n); while (--N > 0); })

but that's not C.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B