C operator precedence mnemonics

Peter Klausler pmk at craycos.com
Thu Jul 5 02:44:02 AEST 1990


In article <1990Jul1.065531.18620 at acc.stolaf.edu> hannum at haydn.psu.edu (Charles Hannum) writes:

> In a lot of cases, C operator precedence sucks.  (I can quote K&R saying the
> same thing -- different wording, of course.  Lets not argue about this point.)
> How does one deal with it?

> My solution:  Most of the time I know.  When I don't, I try it one way, and if
> it doesn't work right, I put parentheses in to force the issue.  Many times I
> just add them to begin with.

C precedence:
	postfix, prefix, multiplication, add, shift, inequality, equality,
	bitwise AND, XOR, OR, logical AND, OR, ternary, assignment, comma

It's easy to derive mnemonics to help you remember this. Here's some
possibilities:

	Please put mice and such in each bag, Alice; except, omit
	lemmings and opossums - they aren't cute.

	PSUVM posts messages, and some involve Evil BIFF. Asinine expression
	often locates available opportunities to access communications.

	Pillsbury Poppin-fresh muffins are so inedible. Every bite aches
	excrutiatingly. Oh, lip agony! oh, tongue agony! call 911!

	Parsing precedences makes a simple implementation elusive. Big,
	automatically-executed, ordinary LR algorithms often take all core.

	Peter's process mangled addresses so important, Eric's bug analyzer
	executed old libraries, and oh! the administrator's confusion!

If you prefer "relation" to "inequality" for {<,<=,>=,>}, then you could use:

	"Presidents prefer moronic actions," said Reagan. "Even Bush allows
	execution of lame activities, only to aggravate Congress."

-Peter Klausler, writing compilers at Cray Computer Corp. in Colorado Springs



More information about the Comp.lang.c mailing list