Re: Fundamental question
From: Chris Dollin (kers_at_hpl.hp.com)
Date: 06/07/04
- Next message: Tomas Deman: "borland time_t conversion"
- Previous message: Ken Tough: "Explicit unsigned/signed conversion: ANSI/ISO rules?"
- In reply to: Guillaume: "Re: Fundamental question"
- Next in thread: Guillaume: "Re: Fundamental question"
- Reply: Guillaume: "Re: Fundamental question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 07 Jun 2004 13:51:11 +0100
Guillaume wrote:
>>>Binary logic operators have the same priority, as far as I know.
>>
>> [...]
>>
>> You're mistaken. Please consult a book or other reference before
>
> Thanks. I don't need to, though. I've been using C for more than 10
> years in professional settings. ;-)
>
> There is a precedence scheme when using && and || logic operators
> in C, but it's not equivalent to algebraic priority, because
> it not only depends on the operators, but on the values of the
> boolean arguments as well.
Wrong. The precedence is syntactic, and [hence] independant of the
values of the operands.
> Thus, this doesn't qualify as classic
> priority, and technically, yes, we can absolutely say that && and
> || have the same priority,
No. See below.
> albeit with a particular behavior
> that, of course, must be known when using C.
>
> In particular, a && b is not functionally equivalent to b && a
> if a or b have side-effects.
Yes. This, however, to do with order-of-evaluation, *not* precedence.
Precedence [and associativity] allows us to determine that
a || b && c means a || (b && c)
not (a || b) && c
which differ when (a=true and c=false), with not a side-effect
in sight, nor any dependance on short-circuit evaluation.
[Clearly if these operators right-associated, I could produce
another counter-example by switching || and &&].
Thus your claim of "equal priority" is refuted.
> The aforementioned expression was deterministic, but highly
> unreadable. This is the point I was making.
"Highly unreadable" is a rather intense way to say "potentially
confusing".
-- Chris "electric hedgehog" Dollin C FAQs at: http://www.faqs.org/faqs/by-newsgroup/comp/comp.lang.c.html C welcome: http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
- Next message: Tomas Deman: "borland time_t conversion"
- Previous message: Ken Tough: "Explicit unsigned/signed conversion: ANSI/ISO rules?"
- In reply to: Guillaume: "Re: Fundamental question"
- Next in thread: Guillaume: "Re: Fundamental question"
- Reply: Guillaume: "Re: Fundamental question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|