Boost logo

Boost :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2006-01-06 17:18:18


Peter Dimov wrote:
> If the interface takes unsigned char, passing 322 will result in the
> function receiving 66. This may generate a compiler warning, or it may not.
> Even if it does generate a warning, an explicit static_cast to unsigned char
> (because the programmer thinks that the value is in range) will silence it.

I don't get it. I won't surprise anyone if I'll say that the whole point
of xxx_cast is to signal the programmer who writes this code that he's
doing something fishy, and he should carefully check if this is ok. The
best thing a library writer can do, is to provide the maximum compiler
checks that will produce either an error or a warning in case of
suspicious usage. Forcing the user to use a red-flagged cast is exactly
such an example. If the user chose to supress the warning using a cast,
then we could only assume he knows what he's doing.

Runtime checks are inferior because they
A) hurt performance
B) make code cumbersome
so compile-time check are prefered.

Was there anything new and surprising in what I just said? I think not...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk