why bother with operator precedence

Tom Neff tneff at bfmny0.UU.NET
Tue Mar 27 18:21:24 AEST 1990


In article <2031 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>It is much worse.  The precedence rules in algebra are well known, but the
>arbitrary ones in C are not, and are not intuitive.  What is the precedence
>for 
>
>		a << b + c 

I think the point was that you should say what you mean, i.e.

		(a << b) + c
or
		a << (b + c)

as appropriate, in code that you write.  I try to do this myself in
cases where there might be any doubt among those who don't have
prefrontal YACC implants :-).

However it's probably a good idea to run C students through the list,
because they will someday have to READ code as well as write it.

It would also be nice to write and pass around a tiny public domain
utility that takes any C expression and parenthesizes it to the max.
-- 
"How can a man of integrity get along    ///  Tom Neff
in Washington?" -- Richard Feynman      ///   tneff at bfmny0.UU.NET



More information about the Comp.lang.c mailing list