Hi,
Is there any difference between
header = hdr_type & 0x80 ; and
This makes header either 0 or 0x80.
header = !!(hdr_type & 0x80);
This makes header either 0 or 1, since '!' yields either 0 or 1. This
can be confusing because it ignores a well-known law of boolean logic:
!!a = a; double negation has no effect and can be removed. It doesn't
work that way here because C's notion of a boolean is not that of a
two-value type, so !! does have effect and actually "converts" its
argument to a one-bit value. Its value as a boolean is still unchanged,
though: for a boolean test it doesn't matter whether you test on 1 or 0x80.
I have seen the second kind of assignment in some places.Does it have
any special reason ?
Yes, it's an (in my opinion) less intuitive way of writing
header = hdr_type & 0x80 ? 1 : 0;
Of course, if you only use 'header' as a boolean, in tests, there is no
need for this in the first place and you can just use 'hdr_type & 0x80'.
S.