Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Priorities of = and == again (c'mon you ANSI freaks) Message-ID: <665@PT.CS.CMU.EDU> Date: 18 Jan 88 15:05:43 GMT References: <1171@ark.cs.vu.nl> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 41 In article <1171@ark.cs.vu.nl>, maart@cs.vu.nl (Maarten Litmaath) writes: > Lately I asked why the priorities of = and == were not reversed: > > while ((c = getchar()) == ' ') > > is used much more than > > while (c = getchar() == ' ') > . > I argued that ONLY programs containing code of the second form, > need to be rewritten using parentheses; occurrences of those > expressions are not hard to find using shelltools (SUN, yeah). > Concluding, I'm not very impressed by the 'backward compatibility' > argument used by ANSI and by Doug Gwyn, who responded to my previous > article (thanks, Doug). > Any further thoughts on this ? Changing the precedence rules will will break more than just those while loops that you are complaining about. Consider found = key == entry.key; Perfectly valid and it is pretty obviously that the programmer didn't intend the expression to be parsed as: (found = key) == entry.key; which is what would happen if you change the precedence of "=" to be higher than "==". Then again, we could change it such that in the context of either "while" or odd number Tuesdays of an even number month "=" has a higher precedent than "==". :-) BTW I usually parenthesises expressions involving boolean assignment to make it clearly as to what is going on: found = (key == entry.key); -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu