Setting Extra Bits In Bool

Asked By 10 points N/A Posted on -
qa-featured

If I get a Boolean variable and put its second bit at 1, the variable is evaluated as true and false at the same time. Compile the following code with gcc6.3 with the -g option (gcc-v6.3.0 / linux / RHEL6.0-2016-x86_64 / bin / g ++ -g main.cpp -o mytest_d) and run the executable. File off. You get the following.How can one be true and false at the same time?

SHARE
Answered By 0 points N/A #318467

Setting Extra Bits In Bool

qa-featured

You’ve probably heard somewhere that “zero is wrong” and “non-zero is true”. This is true if you stick to the language parameters and statically convert an int to a bool or vice versa.It does not stop when you start playing with bitmaps. In this case, you break your contract and enter the behavior zone (at least) defined by the implementation.

Do not do that.It’s not up to you to decide how a boolean is stored in memory. This is the compiler. If you want to change the value of a Boolean, set true or false or assign an integer and use the appropriate conversion mechanisms provided by C ++.The C ++ standard used to actually give a specific call, and how to use Bool in this way is naughty, mean and nasty.

Related Questions