My ISP was unable to accept mail from me this weekend, so
I could read the postings, but could not respond.  I'm
still catching up.  

> > (1*(2+3))*(5-4) = 5
> > OR
> > (1*(2+3))*(4-5) = -5
> >
> 
> Good question. This might be 'implementation dependent'... 
> But I think 5-4 would be be the standard
> way: apply MINUS to pop() = 5 and pop() = 4 => (- 5 4) = 5 - 4
> 
> 
> Hans

This is governed by the rules of association.  The simplest
ambiguous case is

        3 - 1 - 1

which could have a result of 3 or 1, depending on the order done.

My copy of "The C Programming Language" has a marker on page 49,
where the 15 different types of operators are listed, together 
with their precedence and direction of association.  

In general, I think that anyone who depends upon this table
should be taken out and shot.  However, there are common 
idioms that depend on the fact that comparison (==, > and 
the like) bind more tightly than && and ||, so you will see

        if (x == 0 || x == 1)

Of course, this is question about precedence, not association.

I will never knowingly give a problem that depends on
knowledge of this kind of factoid, or upon the direction
of association, as I can't keep them straight myself. 
You should sprinkle enough parenthesis that the reader
or compiler is never in doubt about your intentions.  

- jeff parker

Reply via email to