|
Boost : |
From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2002-09-28 04:14:18
"Daryle Walker" <darylew_at_[hidden]> wrote in message
news:4B16B976-D2AF-11D6-85D1-0003939C8002_at_mac.com...
> Couldn't we just use a
>
> return static_cast<unsigned char>( x ^ int_expression )
>
> to safely shut the compiler up? Of course, "x" is an unsigned char so
> maybe it needs to be converted too.
I personally don't like using static_cast in such a way - it clutters the
code and suggests a hack, IMO. Anyway, I tried the following three
alternatives which I would have expected to work, but none of them did.
return static_cast<unsigned char>(x ^ ( rem >> (DoReflect ? 0u : Bits -
CHAR_BIT) ) );
return x ^ static_cast<unsigned char>( ( rem >> (DoReflect ? 0u : Bits -
CHAR_BIT) ) );
return static_cast<unsigned char>( x ^ static_cast<unsigned char>( ( rem >>
(DoReflect ? 0u : Bits - CHAR_BIT) ) ) );
Is my original fix of this (modified slightly in response to Dirk Gerrits)
really that much of a performance hit? I don't know without running some
tests.
return UCHAR_MAX & (x ^ ( rem >> (DoReflect ? 0u : Bits - CHAR_BIT) ) );
BTW, I don't think this is the only like containing this problem, but it is
the only one I have hit in my (limited) use of CRC library. For example,
lines 538 and 573 also exhibit similar code.
Regards
--Craig
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk