[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] maint: Use logical rather than bitwise operators on bools

From: Paul Eggert
Subject: Re: [PATCH] maint: Use logical rather than bitwise operators on bools
Date: Wed, 23 Sep 2009 15:39:33 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Pádraig Brady <address@hidden> writes:

> I did also check the speed with a test program
> (attached) which showed the logical test was a bit faster on my pentium-m.
> Note I compiled without optimization

I would expect optimization would be crucial: I got the 60% increase
in number of instructions for && when compiling with optimization, and
without optimization there was almost no difference between && and &.

Although I admit that it bugs me that the change makes the code slower
and fatter, my primary objection is that short-circuit AND has more
complicated semantics than Boolean AND, and we shouldn't necessarily
favor the former over the latter.  I agree that the bitwise part of
the logical AND in traditional C 'int' semantics is a problem, but to
my mind it's not a problem that necessarily overwhelms the
short-circuit disadvantage.

If it's safe to assume proper 'bool' support now, that would address
the problem as well.  Perhaps it's better to make that assumption now
anyway, for reasons other than the one prompting this thread.  After
all, the subtle differences between C99 bool and C89
approximately-bool go beyond the && and || problem.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]