| re: How to check if a bit is off?
In message <843a4f78.0408232027.16307f74@posting.google.com >, Old Wolf
<oldwolf@inspire.net.nz> writes[color=blue]
>Richard Herring <junk@[127.0.0.1]> wrote:[color=green]
>> Old Wolf writes:[color=darkred]
>> >"Siemel Naran" <SiemelNaran@REMOVE.att.net> wrote:
>> >>
>> >> Question: what is the type of !(d_flags & flag ).
>> >
>> >The results of && || ! are all int.[/color]
>>
>> Not according to ISO14882 sections 5.3.1, 5.14 and 5.15:
>> "The result is a bool".[/color]
>
>How right you are
>[color=green][color=darkred]
>> >> This would mean converting an int to bool, which I imagine is internally
>> >> something like
>> >>
>> >> if (value != 0) result = 1;
>> >> else result = 0;
>> >>
>> >> Thus !(d_flags & flag) is
>> >>
>> >> if (d_flags & flag == 0) result = 1;
>> >> else result = 0;
>> >
>> >I don't know why so many people have misgivings about "int to bool
>> >conversions".[/color]
>>
>> I don't know why so many people have misgivings about the argument and
>> result types of !, && and ||.[/color]
>
>It's different in C.[/color]
It would have to be. C had no bool type.
[color=blue]
>But this is a different issue to int-to-bool
>conversions, which the OP was asking about.
>[color=green][color=darkred]
>> >false is zero and true is non-zero. This was the case
>> >even before computers were invented. No assembly instructions are
>> >required.[/color]
>>
>> There's at least one architecture where even=>false and odd=>true.[/color]
>
>Irrelevant to C++ (as was the original point, too)[/color]
You're the one who raised assembly instructions.
--
Richard Herring |