Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site gatech.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gatech!arnold From: arnold@gatech.UUCP (Arnold Robbins) Newsgroups: net.lang.c Subject: Re: C-Debug package ... (a la "context-independent macros") Message-ID: <11839@gatech.UUCP> Date: Fri, 1-Feb-85 12:12:18 EST Article-I.D.: gatech.11839 Posted: Fri Feb 1 12:12:18 1985 Date-Received: Sat, 2-Feb-85 12:46:56 EST References: <1885@wateng.UUCP> <1089@hcrvx1.UUCP> <33@daisy.UUCP> <1097@hcrvx1.UUCP> <1924@wateng.UUCP> Organization: Firefighters Extraordinaire, Inc. Lines: 39 Okay, folks, we've discussed this one before. The macro #define assert(x) if (!(x)) die_miserably("x bombed\n") doesn't work because of problems with a missing else. It was suggested #define assert(x) if (!(x)) die_miserably("x bombed\n") else /* no ; */ but if the real semicolon is left off by accident, the next statement is eaten. Now, putting braces around it also won't work: #define assert(x) { if (!(x)) die_miserably("x bombed\n"); } because of this: if (something) assert (something_else);/* <--- this ; will bomb cc */ else another_thing_altogether(); So, as has been mentioned before, the two ways to do this are #define assert(x) do { if (!(x)) die_miserably("x bombed\n"); } while (0) which will get executed exactly once, and protects the macro syntactically. This also should not pose a code generation/efficiency problem. The other way is this: #define assert(x) if(x) ; else die_miserably ("x bombed\n") which will also work. This topic has gone around (several times) before. I am hoping that this note will settle it, so that we can discuss something else. Thanks, -- Arnold Robbins CSNET: arnold@gatech ARPA: arnold%gatech.csnet@csnet-relay.arpa UUCP: { akgua, allegra, hplabs, ihnp4, seismo, ut-sally }!gatech!arnold Help advance the state of Computer Science: Nuke a PR1ME today!