F
Frederick Gotham
Does "bool" behave _exactly_ like any other integer type, except for when it
comes to integer promotion? Consider the following C function whose purpose
it is to calculate the quantity of equal coordinates:
struct Coord3D {
int a,b,c;
};
typedef struct Coord3D Coord3D; /* To make it work like C++ */
unsigned QuantSame(Coord3D const *const x,Coord3D const *const y)
{
return (x->a == y->a)+(x->b == y->b)+(x->c == y->c);
}
In C, the type of the result of the equality operation would be "int", and
these int's can be added together.
In C++, however, the type of the result of the equality operation is "bool".
Am I right in thinking, that, when arithmetical operations are performed upon
a bool, that it undergoes integer promotion just like any other integer type?
(except that it _must_ become either 0 or 1).
Are there any other places in which a bool doesn't behave like it's just
another built-in integer type?
comes to integer promotion? Consider the following C function whose purpose
it is to calculate the quantity of equal coordinates:
struct Coord3D {
int a,b,c;
};
typedef struct Coord3D Coord3D; /* To make it work like C++ */
unsigned QuantSame(Coord3D const *const x,Coord3D const *const y)
{
return (x->a == y->a)+(x->b == y->b)+(x->c == y->c);
}
In C, the type of the result of the equality operation would be "int", and
these int's can be added together.
In C++, however, the type of the result of the equality operation is "bool".
Am I right in thinking, that, when arithmetical operations are performed upon
a bool, that it undergoes integer promotion just like any other integer type?
(except that it _must_ become either 0 or 1).
Are there any other places in which a bool doesn't behave like it's just
another built-in integer type?