Boost logo

Boost :

From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2002-09-23 04:57:15

"Vladimir Prus" <ghost_at_[hidden]> wrote in message
> Craig Henderson wrote:
> > There is a small problem with the CRC library that is shown up at
> > with the MSVC7 compiler option "Smaller Type Check" /RTCc. The problem
is in
> > crc.hpp at line 550 which reads
> >
> > { return x ^ ( rem >> (DoReflect ? 0u : Bits - CHAR_BIT) ); }
> >
> > Changing this to
> > { return 0xff & (x ^ ( rem >> (DoReflect ? 0u : Bits - CHAR_BIT) ) ); }
> >
> > solves the problem.
> Hi Graig,
> can you tell more about that warning? Is it triggered whenever int
> converted to unsigned char has value larger than 255? In this particular
> case, that's precisely what is desired. Is it possible to suppress this
> warning without adding extra operation --- I'm not sure all compilers
> will optimize it.

It is not a compilation warning, but a runtime check which pops up a message
box and is therefore very annoying. The option can be turned off, of course,
but I like to run with maximum safety checking when developing code.
The Smaller Type Check will through up a runtime error is a conversion to a
smaller type occurs. In this case, the conversion to unsigned char truncates
the source data type to 8 bits and throws the error. Like you say, this is
the required behaviour in this situation, and therefore a simple "0xff &
(...)" is enough to be specific about the required result. I've not tested
the optimisation of this, but I would not expect any problems.

-- Craig

Boost list run by bdawes at, gregod at, cpdaniel at, john at