Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!groucho!steve From: steve@groucho.ucar.edu (Steve Emmerson) Newsgroups: comp.lang.c Subject: Re: Problem with #define'd macro... Message-ID: <10868@ncar.ucar.edu> Date: 2 Apr 91 04:11:47 GMT References: <1991Mar20.150301.9941@evax.arl.utexas.edu> <1099@gtenmc.UUCP> Sender: news@ncar.ucar.edu Organization: University Corporation for Atmospheric Research (UCAR) Lines: 50 In <1099@gtenmc.UUCP> ravim@gtenmc.UUCP (Vox Populi) writes: >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. I believe the above statement is false because 1) the string in question (which is an expression): a == b ? c=d, e=f : g=h, i=j can be generated from the K&R1 grammar; and 2) precedence is irrelevant in determining whether or not a string is valid. The expression-string can be generated from the following sequence of production rules (Appendix A, K&R1): exp ? exp : exp exp binop exp ? exp , exp : exp , exp primary == primary ? lvalue asgnop exp , lvalue asgnop exp : lvalue asgnop exp , lvalue asgnop exp identifier == identifier ? identifier = primary, identifier = primary : identifier = primary, identifier = primary a == b ? c=identifier, e=identifier : g=identifier, i=identifier a == b ? c=d, e=f : g=h, i=j Precedence, on the other hand, is a tool used by parsers to disambiguate between two or more ways of generating the same string from a given grammar. The validity of a given string, however, is determined solely on the basis of whether or not it can be generated by the production rules of the grammar. Since the above string can, then it's valid under the K&R1 grammar. This might seem counter intuitive and, indeed, Standard C has closed this `loophole' by redefining the production rules in such a manner that the above string cannot be generated. Steve Emmerson steve@unidata.ucar.edu ...!ncar!unidata!steve