Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!bbn!bbn.com!mesard From: mesard@bbn.com (Wayne Mesard) Newsgroups: comp.lang.c Subject: Re: ambiguous why? Message-ID: <22997@bbn.COM> Date: 5 Apr 88 15:31:31 GMT References: <1303@PT.CS.CMU.EDU> Sender: news@bbn.COM Lines: 47 From article <1303@PT.CS.CMU.EDU>, by edw@IUS1.CS.CMU.EDU (Eddie Wyatt): > I got an > error message that said something to the extent: > > warning ambiguous assigment: assignment op taken > syntax error at or near symbol *= > > A simplified version of the statement is: > > int *a, *b; > > *a+=*b; > > I thought that this should not be ambiguous since the lexer scans left to right. K&R A.17 talks about earlier versions of C which used the form "=op" instead of "op=". Most(?) compilers still try to detect the old form and issue a warning. In my opinion this causes headaches more than it catches obsolete code. Anyway, the compiler wasn't sure if you wanted "addition assignment" (+=) or the old multiplication assignment (=*) so it complained. Putting a space after the "=" fixes it: int *a, *b; *a+= *b; I usually run into this in the first expression of a for statement: for (a=-1; ++a < N;) ... Which serves me right, since readability and good taste dictate that I should have spaces around my assignment ops anyway. Now here's one for you puritans and compiler whiz-kids: K&R 7.14 says "The two parts of a compound assignment operator are separate tokens." Doesn't this mean that the spaces (absense or presense of) shouldn't matter? Indeed they are separate tokens since the following code works: a + = b; -- unsigned *Wayne_Mesard(); MESARD@BBN.COM BBN Labs, Cambridge, MA After all, Sodom wasn't built in a day.