Re: Fundamental question

From: Keith Thompson (kst-u_at_mib.org)
Date: 06/07/04


Date: Mon, 07 Jun 2004 21:18:43 GMT

Guillaume <grsNOSPAM@NO-SPAMmail.com> writes:
> > Thus your claim of "equal priority" is refuted.
>
> Is it? I'm not sure you understood what I meant by that.
>
> If && and || don't have equal priority, which of them
> has higher priority then? Good luck. ;-)
>
> Both logical operators guarantee left-to-right evaluation,
> and that is it. This does not add up to different priority
> in the algebraic sense, as in: 'A + B * C'. This is what
> I meant. '*' has higher priority than '+'.
>
> Is what I said clearer now?

No, it isn't.

I thought you were making some distinction between priority and
precedence, but I don't think you are.

A + B * C is equivalent to A + (B * C), so "*" has higher precedence
than "+".

A || B && C is equivalent to A || (B && C), so "&&" has higher
precedence than "||".

The "&&" and "||" operators are evaluated left-to-right, with
short-circuit semantics, but that's a separate issue. For "+" and
"*", precedence is a question of which operators apply to which
operands; it's more syntactic than semantic. The precedence of the
"&&" and "||" operators is determined in exactly the same way.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.


Relevant Pages

  • Re: Fundamental question
    ... between "priority" and "precedence" (though if you meant to make such ... a distinction you should have made it clear in the first place). ... Any C programmer needs to know ...
    (comp.lang.c)
  • issues with SO_PRIORITY and IP_TOS
    ... tos field to generate the packet priority value. ... backwards compatible with the old precedence field. ... for vlan priority tagging there are only 3 bits available. ... The second call sets the proper socket priority so ...
    (Linux-Kernel)
  • Re: Fundamental question
    ... Please consult a book or other reference before ... > in C, but it's not equivalent to algebraic priority, because ... The precedence is syntactic, ... > if a or b have side-effects. ...
    (comp.lang.c)