Using Macros

Peter Holzer hp at vmars.tuwien.ac.at
Fri Aug 10 02:23:55 AEST 1990


volpe at underdog.crd.ge.com (Christopher R Volpe) writes:

>In article <46860 at brunix.UUCP>, gvr at cs.brown.edu (George V. Reilly) writes:
>|>Ah, but Karl, you missed the more important bug that Brad should have
>|>used &&, not ||.  In Brad's example, exit() will only be called if
>|>cond == 0, which is exactly the inverse of what is desired.  The same is
>|>true of your second offering.

>What makes you think that is what was desired? I interpret "CHECK(cond)"
>the same way I interpret "ASSERT(cond)", which is "continue iff cond is true".
>I.e., exit when cond is false. Under this interpretation, "||" is correct.

What made ME think that this s what was desired is this line in the original 
posting:
From: brad at SSD.CSD.HARRIS.COM (Brad Appleton)
> 
> 	#define CHECK(cond)  { if (cond)  exit(-1);  }
> 
which is certainly not equivalent to:
> 
> 	#define CHECK(cond)  ((cond) || exit(-1))
> 
but to
#define CHECK(cond)  ((cond) && exit(-1))

Karl obviously interpreted it the same way or he would not have
suggested:

From: karl at haddock.ima.isc.com (Karl Heuer)
>	#define CHECK(cond)  ((cond) ? exit(-1) : (void)0)

It is amazing though, that the Walking Lint missed the ||-&& confusion.
Oh well, the program would miss it too :-)
--
|    _	| Peter J. Holzer			| Think of it	|
| |_|_)	| Technische Universitaet Wien		| as evolution	|
| | |	| hp at vmars.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!vmars!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list