Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!botter!sjoerd From: sjoerd@botter.UUCP (sjoerd) Newsgroups: net.lang Subject: Re: null statements Message-ID: <593@botter.UUCP> Date: Fri, 25-Jul-86 06:54:26 EDT Article-I.D.: botter.593 Posted: Fri Jul 25 06:54:26 1986 Date-Received: Fri, 25-Jul-86 21:55:57 EDT References: <800015@ccvaxa> <463@opus.nbires.UUCP> <442@sunybcs.UUCP> <484@valid.UUCP> <2565@umcp-cs.UUCP> Reply-To: sjoerd@vu44.UUCP (Sjoerd Mullender) Organization: VU Informatica, Amsterdam Lines: 29 In article <2565@umcp-cs.UUCP> chris@maryland.UUCP (Chris Torek) writes: [ About null statements in #defines ] >In many cases the function is more complex: > > #define SaveB(b) \ > if ((b)->b_AfterGroupRst == NULL || \ > (b)->b_AfterGroupRst->sv_level != CurrentGroup) \ > DoSave(b); \ > else \ > /* do nothing */ > And continues to suggest a few solutions since the above will wreak havoc if you forget a semicolon in the call. Another solution (which does not require a null statement) is: #define SaveB(b) \ (/* if */ ((b)->b_AfterGroupRst == NULL || \ (b)->b_AfterGroupRst->sv_level != CurrentGroup) /* then */ && \ DoSave(b)) I agree that this may be bit confusing, but this has the great advantage that you can use it everywhere where you can use an expression (like in a for statement). Another use for this construct is the assert macro: #define assert(e) (!(e) && printf("Assertion failed ...")) You can write this differently: #define assert(e) ((e) || printf("Assertion failed ...")) I like this much better than the if statement that is usually used. >In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) >UUCP: seismo!umcp-cs!chris >CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu