Why is the first one able to increment pbf_[k] correctly while the second one does not even do it(increment)for once?
unsigned pbf_[5] ={0};
bool m=0;
Code 1:
for(int k=0;k<5;k++)
{
if((m=(bit_table_[k][i][bit_index ] &bit_mask[bit]))==true)
pbf_[k]++;
}
Code 2:
for(int k=0;k<5;k++)
{
if((bit_table_[k][i][bit_index ] & bit_mask[bit])==true)
pbf_[k]++;
}
In the first case, the result of the masking is converted to bool m
before it is compared to true.
In the second case, I believe the bitmasks are some integer type. In that case true
will be promoted to the same integer type (and have the value 1).
Just remove the == true
from the comparison to make them equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With