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
mbefore it is compared to true.In the second case, I believe the bitmasks are some integer type. In that case
truewill be promoted to the same integer type (and have the value 1).Just remove the
== truefrom the comparison to make them equivalent.