[comp.lang.c] C operator precedence mnemonics

pmk@craycos.com (Peter Klausler) (07/04/90)

In article <1990Jul1.065531.18620@acc.stolaf.edu> hannum@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

herrera@tegra.COM (Valentino Herrera) (07/07/90)

In article <1990Jul4.164402.2072@craycos.com> pmk@craycos.com (Peter Klausler) 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?
>
>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.

Perhaps people might add some instances. Even bombastic, aggrevating examples
of linguistic assignments are often times antagonistically complicated. Can
anyone help?



-- 
+---------------------------------------------------------------+
|Valentino Herrera   Tegra/Varityper  tegra!herrera@ulowell.edu |
|              "And the meek shall inherit s**t"                |
+---------------------------------------------------------------+