M
Mike Wahler
Bob Hairgrove said:Well, it does compile and run correctly under Comeau, returning 1:
Because 'true' is output as '1' (and 'false' as 0) by operator<<,
by default (via a facet of a locale). (This behavior can be changed
(with the 'boolapha' format flag or manipulator).
#include <iostream>
#include <ostream>
int main()
{
std::cout << "Result of !((1 || 0) && 0):\t";
std::cout << !((1 || 0) && 0) << std::endl;
return 0;
}
After all, bool is defined by the standard to be
"an integral type".
Question is, whether other output != 0 (e.g. 4711) should be allowed.
Does the standard specify what the integral value of "true" should be?
======================================================================
ISO/IEC 14882:1998(E)
4.5 Integral promotions
4 An rvalue of type bool can be converted to an rvalue of type int,
with false becoming zero and true becoming one.
======================================================================
-Mike