Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cubsvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!cmcl2!rna!cubsvax!peters From: peters@cubsvax.UUCP (Peter S. Shenkin) Newsgroups: net.lang.c,net.unix-wizards Subject: Re: how has C bitten you? Message-ID: <356@cubsvax.UUCP> Date: Mon, 26-Aug-85 09:24:49 EDT Article-I.D.: cubsvax.356 Posted: Mon Aug 26 09:24:49 1985 Date-Received: Wed, 28-Aug-85 21:15:12 EDT References: <302@brl-tgr.ARPA> <471@baylor.UUCP> <148@chinet.UUCP> <> Reply-To: peters@cubsvax.UUCP (Peter S. Shenkin) Organization: Columbia Univ Biology, New York City Lines: 27 Xref: watmath net.lang.c:6177 net.unix-wizards:14583 Summary: I've sometimes bitten myself with MACRO definitions... read on! I've had several bugs involving code hidden in macro definitions which have been very difficult to find. One I recall offhand went something like this: /* OPEN MOUTH *****************************************************************/ #define Coords(I) (complicated.structure.redirection[I].x, \ complicated.structure.redirection[I].y, \ complicated.structure.redirection[I].z ) main() { ... subr(Coords(i)); /* BITE */ ... } /***************************************************************************/ subr(x,y,z) float x,y,z; {...} /* SWALLOW ******************************************************************/ Problem is, when expanded, the call to subr looks like subr((exp1,exp2,exp3)); The comma operator is applied, and subr() gets only exp1 !!! The interesting thing is that if anyone had asked me, whether (something), ((something)), and (((something))) mean the same in C, I would have said "Yes," without thinking. Obviously, I would have been wrong. Peter S. Shenkin philabs!cubsvax!peters Columbia Univ. Biology