Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!pilchuck!dataio!gtenmc!ravim From: ravim@gtenmc.UUCP (Vox Populi) Newsgroups: comp.lang.c Subject: Re: Problem with #define'd macro... Message-ID: <1099@gtenmc.UUCP> Date: 29 Mar 91 01:55:30 GMT References: <1991Mar20.150301.9941@evax.arl.utexas.edu> Reply-To: ravim@gtenmc.UUCP (Ravi Kumar Mandava) Organization: GTE Telecom, Inc. Bothell, WA Lines: 27 In article <1991Mar20.150301.9941@evax.arl.utexas.edu> c145gmk@utarlg.uta.edu writes: >Attempting to compile the following (fragment, but displays the problem) >results in an 'invalid target for assignment' error on our VAX running > >#define DIV_MOD(d,r,x,y) ( y == 0.0 ? d = 0.0, r = x : d = x/y, r = x - d*y ) >a = 5, b = 2; DIV_MOD(quotient,remainder,a,b); I think the compiler error that you were getting is because, operator precedence is not observed here correctly. According to K&R precedence table, operator ',' has lower precedence (in fact, least precedence) than the tertiary operator '? :'. Hence you would need to raise the precedence of ',' operators in the operands of '? :' in the macro defined above. Hence, the correct definition would be #define DIV_MOD(d,r,x,y) ( y == 0.0 ? (d = 0.0, r = x) : (d = x/y, r = x - d*y)) - Ravi Mandava -- ********************** #include ************************** Ravi Mandava e-mail : ravim@gtenmc.gtetele.com or ravim@gtenmc.UUCP *******************************************************************************