develooper Front page | perl.perl5.porters | Postings from February 2006

Re: &= vs. |= and ^= (was: This Fortnight on perl5-porters (6-19 February 2006))

Thread Previous | Thread Next
Stephen McCamant
February 25, 2006 15:02
Re: &= vs. |= and ^= (was: This Fortnight on perl5-porters (6-19 February 2006))
Message ID:
>>>>> "Summary" == David Landgren <> writes:

Summary> "pp_bit_and", "pp_bit_x?or" and "USE_LEFT"

Summary>    Nicholas found an interesting discrepancy between a trio
Summary>    of functions in pp.c. On the one hand "pp_bit_and" does
Summary>    one thing, whereas "pp_bit_or" and "pp_bit_xor" throw a
Summary>    ternary operator into the works for what is otherwise very
Summary>    similar code. It's been there a long time, is touched upon
Summary>    in bug #17809 and Nicholas wanted to know more.

Summary>    No-one appeared to remember anything about it at all.

Summary>      Lost in the mists of time

I think Yitzchak has the right idea that it was a judgment call based
on usefulness. I'm not sure how much of this I'm remembering and how
much I'm recreating, but I think I can flesh this idea out a bit more.

Nicholas is also right that it's analogous to *= and +=. For + and |,
zero is the identity, so depending on uninitialized variables being
zero will do the right thing for common cases like summing all of the
elements in a list. On the other hand, using 0 with * or & will always
give a zero result, so an &= or a *= on an uninitialized variable will
be a no-op. This is a good hint that it isn't doing what the user
intended, so it's a safer candidate to warn about (as with the
"useless use of ... in void context" warnings).

 -- Stephen

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About