This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Boolean equality (C++/Fortran)
David Lecomber <david@streamline-computing.com> writes:
> In valarith.c:value_binop, where v1 and v2 have been established to be
> values of type bool, we have:
>
> case BINOP_EQUAL:
> v = v1 == v2;
> break;
>
> case BINOP_NOTEQUAL:
> v = v1 != v2;
> break;
>
> Isn't this wrong? If you are mixing your compilers, then, at least for
> Fortran, the actual value of true can vary (1 or -1 I have so far
> seen). For C++ this is less likely to happen, and so far as I can tell
> changing the above would not harm anything.
>
> Does anyone have any comments on replacing the above with:
>
> case BINOP_EQUAL:
> v = !((!v1 && v2) || (v1 && !v2));
> break;
>
> case BINOP_NOTEQUAL:
> v = (!v1 && v2) || (v1 && !v2);
> break;
The general idea looks right. But how about:
> case BINOP_EQUAL:
> v = !v1 == !v2;
> break;
>
> case BINOP_NOTEQUAL:
> v = !v1 != !v2;
> break;