Using Macros

Brad Appleton brad at SSD.CSD.HARRIS.COM
Fri Aug 10 03:55:04 AEST 1990


In article <46860 at brunix.UUCP> gvr at cs.brown.edu (George V. Reilly) writes:
>! %    	#define CHECK(cond)  { if (cond)  exit(-1);  }
>! %    could be replaced by
>! %    	#define CHECK(cond)  ((cond) || exit(-1))
>! %    
>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.

Actually, it was the IF statement I messed up, not the "||". I want the program
to exit only if the condition is false (like an assertion).

Sorry about that!
I was more concerned with illustrating a (possibly new) technique and didnt
pay close enough attention to the example I used. The dup2() macro that I
posted in the same article I have used before (succesfully).

Actually, that dup2() macro is in a small piece of code that I wrote
specifically for illustrating how to fork off a process and have the parent
read the output from the child. It seems to be asked frequently (even though
it is Unix specific). Should I submit my file to the FAQ list?

______________________ "And miles to go before I sleep." ______________________
 Brad Appleton        brad at travis.ssd.csd.harris.com   Harris Computer Systems
                          ...!uunet!hcx1!brad          Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~



More information about the Comp.lang.c mailing list