Operator symbol for "nb_intdivide"
Bernhard Herzog
bh at intevation.de
Fri Jul 27 09:38:27 EDT 2001
Guido van Rossum <guido at zope.com> writes:
> > > I don't believe this. If you can't distinguish / from //, you need
> > > new glasses. :-)
> >
> > Hmmmm. Not sure I believe this; mistaking "|" for "||" is said to be
> > a frequent cause of errors in C code.
>
> For different reasons: they have different priorities but their
> meaning is related (both are "or", just one is bitwise and the other
> is Boolean shortcut). Programmers coming from languages where only
> "|" existed were tempted to use that, but the priorities are so broken
> that a==b | c==d is parsed as (a == (b|c)) == d.
Interesting that even a language designer with lots of C-experience can
get this wrong :) | has in fact almost the same precedence as || and
it's in fact lower than the comparison operators, so that a==b | c==d is
actually parsed as the user expected ( (a == b) | (c == d)) so it even
works as expected, although in cases where the operands are e.g. a
normal int and a comparison this is likely to break down.
The problem with |'s and &'s precedence in C is that in an expressions
like 0x0f == a & 0x0f, which seems to test whether the 4 lower bits of a
are 1, is in fact parsed as (0x0f == a) & 0x0f.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://mapit.de/
More information about the Python-list
mailing list