test-alloc-util: add casts to bools from p ointers
C++03: "An rvalue of arithmetic, enumeration, pointer, or pointer to member type can be converted to an rvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true" C should behave the same because pointers are scalars in C, but let's verify that.
This commit is contained in:
parent
5d904a6aaa
commit
108ccae9e1
|
@ -58,19 +58,23 @@ static void test_memdup_multiply_and_greedy_realloc(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_bool_assign(void) {
|
static void test_bool_assign(void) {
|
||||||
bool b, c, *cp = &c, d, e, f;
|
bool b, c, *cp = &c, d, e, f, g, h;
|
||||||
|
|
||||||
b = 123;
|
b = 123;
|
||||||
*cp = -11;
|
*cp = -11;
|
||||||
d = 0xF & 0xFF;
|
d = 0xF & 0xFF;
|
||||||
e = b & d;
|
e = b & d;
|
||||||
f = 0x0;
|
f = 0x0;
|
||||||
|
g = cp; /* cast from pointer */
|
||||||
|
h = NULL; /* cast from pointer */
|
||||||
|
|
||||||
assert(b);
|
assert(b);
|
||||||
assert(c);
|
assert(c);
|
||||||
assert(d);
|
assert(d);
|
||||||
assert(e);
|
assert(e);
|
||||||
assert(!f);
|
assert(!f);
|
||||||
|
assert(g);
|
||||||
|
assert(!h);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
Loading…
Reference in a new issue