why no &&= and ||= ?
Author Message
why no &&= and ||= ?

I seldom use the +=, -=, etc. operators.
I just noticed that there are not ||= and &&= operators.
Why? Ambiguity over order of evaluation?

--

Mon, 19 Aug 1996 12:38:50 GMT
why no &&= and ||= ?
: I seldom use the +=, -=, etc. operators.
: I just noticed that there are not ||= and &&= operators.
: Why? Ambiguity over order of evaluation?

: --

Of course there are no ||= and &&=, for they are logical operation.
There *ARE* |= and &=, they are bit operation.

Try to imagine this:

if ( (a==1) ||= (b==1))         puts("they are all 1s.");

ok, if a and b are all 1, then shoule the logical operation result '1'
be assign to a or other?

------ Herbert

Mon, 19 Aug 1996 16:43:36 GMT
why no &&= and ||= ?
|> I seldom use the +=, -=, etc. operators.
|> I just noticed that there are not ||= and &&= operators.
|> Why? Ambiguity over order of evaluation?
|>
|> --

There are |= and &= operators.
--
| Chick Racer                     Chevron Petroleum Technology Co. |
| (713) 596-2430                  P.O. Box 42832                   |

| 4209 Hayes Rd.                                                   |

Mon, 19 Aug 1996 23:27:52 GMT
why no &&= and ||= ?

Quote:

>: I seldom use the +=, -=, etc. operators.
>: I just noticed that there are not ||= and &&= operators.
>: Why? Ambiguity over order of evaluation?

>: --

>Of course there are no ||= and &&=, for they are logical operation.
>There *ARE* |= and &=, they are bit operation.

>Try to imagine this:

>    if ( (a==1) ||= (b==1))         puts("they are all 1s.");

>    ok, if a and b are all 1, then shoule the logical operation result '1'
>    be assign to a or other?

Well, if there *were* a ||= operator, that example would still be
nonsense, because the left operand would have to be an lvalue,
and a==1 isn't an lvalue.

Presumably the proposed operator would allow something like

if (a ||= (b==1)) {
puts("something")

Quote:
}

which would mean

a = (a || (b==1));
if (a) {
puts("something")

Quote:
}

which would make sense.  I suspect the real answer is that unlike
the arithmetic +=, etc, ||= didn't map onto a simple machine
instruction when C was designed.
--
--
-- Don Porges

Tue, 20 Aug 1996 03:26:33 GMT
why no &&= and ||= ?

: Try to imagine this:

I'm trying! :)

:       if ( (a==1) ||= (b==1))         puts("they are all 1s.");

The compiler would say "not an lvalue" -- what's the problem?
It wouldn't allow 3+1 += b+1, why would logical operators be
any different?

I think &&= wasn't included because no one would ever want to
assign the result of a logical expresison often enough
to want to use it.

Of course, ||= would be *FUN* in C++!!!!!! :) For creative overloaders..

Scott

Tue, 20 Aug 1996 06:06:42 GMT
why no &&= and ||= ?
|> I seldom use the +=, -=, etc. operators.
|> I just noticed that there are not ||= and &&= operators.
|> Why? Ambiguity over order of evaluation?

But note that there IS <<= and >>=.  Perhaps they were concerned that ||= and ??=
would require === ;-)

Dave B

Tue, 20 Aug 1996 09:40:04 GMT
why no &&= and ||= ?

Quote:
>|> I just noticed that there are not ||= and &&= operators.
>|> Why? Ambiguity over order of evaluation?
>There are |= and &= operators.

There are also *= and +=.  What's that got to do with it?  You examples

a = 1; /* TRUE */
b = 2; /* also TRUE */

a &= b; /* makes 'a' FALSE! */

whereas

a &&= b; /* makes 'a' TRUE (and presumably 1) */
--
#include        <standard.disclaimer>
_
Kevin D Quitt 91351-4454                96.37% of all statistics are made up

Tue, 20 Aug 1996 12:06:52 GMT
why no &&= and ||= ?

Quote:
>But note that there IS <<= and >>=.  Perhaps they were concerned that ||= and ??=
>would require === ;-)

<<= and >>= are single machine-instructions, as are |= and &=.  && and ||
require multiple instructions.

--
#include        <standard.disclaimer>
_
Kevin D Quitt 91351-4454                96.37% of all statistics are made up

Tue, 20 Aug 1996 12:09:03 GMT
why no &&= and ||= ?
<...Jay Krell wrote (on 3 Mar 94 04:38:50 GMT)...>

Quote:
> I just noticed that there are not ||= and &&= operators.

But, what //I// want is an ^^ operator (logical XOR)!  :-)
(All seriousness aside, it //would// be useful....)

--
Chris Sonnack       | 3M/Information Technology/Engineering Info Svcs

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An intellectual is someone whose mind watches itself

Tue, 20 Aug 1996 12:44:23 GMT
why no &&= and ||= ?

Quote:
>I seldom use the +=, -=, etc. operators.

Out of curiosity: why is it seldom? Just the program code you have come
across in your work? Or do you prefer to use the "a = a + b;" construct
rather than "a += b;" (as a hypothetical example of course)?

FWIW, I happen to find them very useful for certain simplifications in
my code and don't avoid them in my code per se.

Quote:
>I just noticed that there are not ||= and &&= operators.
>Why? Ambiguity over order of evaluation?

Well, || and && are logical operations, not arithmetic. The concept you
are asking for is somewhat meaningless, really.

FWIW, the bitwise operators |, & and ^ do have |=, &= and ^= available.

Z

--
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |

-------------------------------------------------------------------------

Tue, 20 Aug 1996 14:56:38 GMT
why no &&= and ||= ?

Subject: Re: why no &&= and ||= ?

JM>I seldom use the +=, -=, etc. operators.
JM>I just noticed that there are not ||= and &&= operators.
JM>Why? Ambiguity over order of evaluation?

No, || and && are _logical_ operators so using them that way
wouldn't be very useful.

x ||= x    would be the equivalent of x = (x AND x);
x &&= x    would be the x = (x OR x);

The bitwise and and or operators (&= and |=) do exist:

&= assign bitwise AND
|= assign bitwise OR

Tue, 20 Aug 1996 17:13:56 GMT
why no &&= and ||= ?

Quote:

> I seldom use the +=, -=, etc. operators.
> I just noticed that there are not ||= and &&= operators.
> Why? Ambiguity over order of evaluation?

Are you sure you didn't mean the bitwise counterparts & and | of which
there is &= and |=.

|| and && are rarely used outside of conditional expressions and hardly,
if ever used in assignment expressions.

Regards
-Alun
--
| A.Champion                | > I'm incomunicado.

|                           | > About 3 miles from Cognito. (10)

Tue, 20 Aug 1996 22:41:43 GMT
why no &&= and ||= ?

Quote:
> I seldom use the +=, -=, etc. operators.
> I just noticed that there are not ||= and &&= operators.
> Why? Ambiguity over order of evaluation?

Just out of curiosity, what would you have these mean?  Give an example where this
might be useful.  I already know about &= and |=, but these are obviously not the
same thing.

Wed, 21 Aug 1996 03:24:44 GMT
why no &&= and ||= ?

Quote:

>Of course there are no ||= and &&=, for they are logical operation.
>There *ARE* |= and &=, they are bit operation.

>Try to imagine this:

>    if ( (a==1) ||= (b==1))         puts("they are all 1s.");

>    ok, if a and b are all 1, then shoule the logical operation result '1'
>    be assign to a or other?

>                                            ------ Herbert

Herbert seems to be under the impression that the only way to deal
with conditionals is in the context of an if or while clause.

Consider this, Herb:
int flag;
...
flag = (a==1);
...
flag ||= (b==1);      [ or,    flag = flag || (b==1)   ]
...
if (flag)
...

I can't for the life of me think why there are no logical assignment
operators. Although, seeing "===" used somewhere would be amusing :)

--
----
Eric

GCS -d+(---) p+ c+(++) l+ u e+ m+ s+/+ n* h+ f+ g- w+ t+(++) r y?
----

Wed, 21 Aug 1996 08:06:18 GMT
why no &&= and ||= ?

Quote:
>But, what //I// want is an ^^ operator (logical XOR)!  :-)
>(All seriousness aside, it //would// be useful....)

#define LOGICAL_XOR(a, b)       (!(a) ^ !(b))

Ross Ridge

Wed, 21 Aug 1996 19:22:06 GMT

 Page 1 of 2 [ 25 post ] Go to page: [1] [2]

Relevant Pages