How about &&= and ||= ?

Norman Diamond ndiamond at watdaisy.UUCP
Fri Dec 7 06:13:03 AEST 1984


> > Speaking of ^^ and ==== (?!), I always wondered why C didn't have &&= and
> > ||= (with the obvious semantics).
> > 						James Jones
> 
> &= and |= are sufficient already.  Remember ... C doesn't really
> have booleans.

False!  Consider a variable v containing the integer 1, and an expression
that evaluates to 2.
v &= expression;  /* ends up as 0 */
v &&= expression; /* ends up as 1 -- furthermore, expression need not
                                     even be evaluated */

Have I missed something, or why has no one pointed out how the proposed
^^ differs from && and || ?  && and || avoid evaluating their right-hand
operands when unnecessary, and can be used for (e.g.) don't examine array
element if subscript is out of range, don't call function if argument has
certain value, etc.  ^^ must always evaluate both sides.



More information about the Comp.lang.c mailing list