Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!brunix!gvr From: gvr@cs.brown.edu (George V. Reilly) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: <46860@brunix.UUCP> Date: 8 Aug 90 23:29:30 GMT References: <362.26be9dcc@astro.pc.ab.com> <21057@grebyn.com> <642@travis.csd.harris.com> <17298@haddock.ima.isc.com> Sender: news@brunix.UUCP Reply-To: gvr@cs.brown.edu (George V. Reilly) Organization: Brown University Department of Computer Science Lines: 24 In article <17298@haddock.ima.isc.com> karl@kelp.ima.isc.com (Karl Heuer) writes: ! % In article <642@travis.csd.harris.com> brad@SSD.CSD.HARRIS.COM (Brad Appleton) writes: ! % Glad to see a few people finally mentioned the comma operator! Another ! % alternative along those same lines (with similar limitations) is to make ! % use of the logical operators || and &&. Using this, the following: ! % ! % #define CHECK(cond) { if (cond) exit(-1); } ! % ! % could be replaced by ! % ! % #define CHECK(cond) ((cond) || exit(-1)) ! % ! Won't work if exit() is properly declared as void. Try one of ! #define CHECK(cond) ((cond) ? exit(-1) : (void)0) ! #define CHECK(cond) ((cond) || (exit(-1), 0)) ! 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. ________________ George V. Reilly gvr@cs.brown.edu uunet!brunix!gvr gvr@browncs.bitnet Box 1910, Brown U, Prov, RI 02912