Topic: The "new" type bool
Author: "John Burger" <john.burger@compucat.com.au>
Date: 1997/08/14 Raw View
I'm about to lead a certain number of readers down the garden path.
I hope you enjoy the journey!
C++ has recently added a new fundamental type, bool.
You can declare variables of this type:
bool a, b;
You can use these variables where boolean expressions are expected:
if (a) ...
if (b) ...
And you can use these variables in expressions:
if (a && b) ...
if (a || b) ...
Using the bitwise operators, however, seems somehow not strictly kosher,
even though the result is the same:
if (a & b) ...
if (a | b) ...
According to the standard, the compiler has to integer-promote both
variables to either zero or one, perform the bitwise operation, then
convert the result back to a bool for the test. Obviously, the compiler
would probably just operate on the variables directly, but it depended on
their internal representation of bool.
If you agree with everything I've said up until now, then you're at the
dead end I've been leading to and I now want two new operators:
a &&= b;
a ||= b;
They'd only be applicable to bools, since they don't make sense with any
other type.
Somehow,
a &= b;
a |= b;
just don't seem kosher!
John Burger
(Please reply via e-mail)
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: anhaeupl@late.e-technik.uni-erlangen.de (Bernd Anh\dupl)
Date: 1997/08/14 Raw View
In article <01bca85a$07187e60$5e0201c0@owl.compucat.com.au> "John Burger" <john.burger@compucat.com.au> writes:
If you agree with everything I've said up until now, then you're at the
dead end I've been leading to and I now want two new operators:
a &&= b;
a ||= b;
They'd only be applicable to bools, since they don't make sense with any
other type.
Somehow,
a &= b;
a |= b;
just don't seem kosher!
and is not allowed for bool a, since
bool E1;
E1 op= E2;
is explicitly dissallowed by section 5.17 (expr.ass) paragraph 7.
(April 95 Draft).
--
Bernd Anhaeupl Tel.: +49 9131 857787
LATE - Uni Erlangen
Cauerstr. 7 Email: anhaeupl@late.e-technik.uni-erlangen.de
91058 Erlangen
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Gerard Weatherby <gerardw@alum.mit.edu>
Date: 1997/08/15 Raw View
John Burger wrote:
{snip}
> If you agree with everything I've said up until now, then you're at the
> dead end I've been leading to and I now want two new operators:
>
> a &&= b;
> a ||= b;
> John Burger
Assuming your operators existed:
bool a,b;
...
a &&= functionReturningBool( );
b ||= anotherFunction( );
does functionReturningBool execute if a is false?
does anotherFunction execute if b is true?
>
> They'd only be applicable to bools, since they don't make sense with any
> other type.
So we'd introduce new operators, that, unlike almost everything other
operator, couldn't be overloaded?
It's a bit late in the game to introduce operators in the language with
marginal gain. You can always type:
a = a && b;
a = a || b;
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Hyman Rosen <uunet!jyacc!calumny!hymie@ncar.UCAR.EDU>
Date: 1997/08/15 Raw View
"John Burger" <john.burger@compucat.com.au> writes:
> If you agree with everything I've said up until now, then you're at the
> dead end I've been leading to and I now want two new operators:
>
> a &&= b;
> a ||= b;
What's wrong with these instead?
if (!b) a = false; // a &&= b;
if (b) a = true; // a ||= b;
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Steve Clamage <stephen.clamage@eng.sun.com>
Date: 1997/08/17 Raw View
Bernd Anhdupl wrote:
>
>
> ... and is not allowed for bool a, since
>
> bool E1;
>
> E1 op= E2;
>
> is explicitly dissallowed by section 5.17 (expr.ass) paragraph 7.
> (April 95 Draft).
The April 95 draft is not very useful for fine points of the
language. See the FAQ for how to download a copy of the December
96 draft. In it you will find that 5.17 says E1 and E2 must
have arithmetic type, and 3.9.1 "Fundamental types" says that
bool is an arithmetic type.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]