Boost logo

Boost :

From: Kevlin Henney (kevlin_at_[hidden])
Date: 2000-12-10 18:29:15

In message <200012090309.TAA01278_at_[hidden]>, Jesse Jones
<jesjones_at_[hidden]> writes
>>>There's lot of code that really can't be unit tested very effectively.
>>>For example, 3/4 of my numeric casts are probably in my low level Mac GUI
>>>code where I have to convert ints to shorts. It's hard to unit test a
>>>window or a checkbox...
>>In which case, it seems quite clear that what you need here is a
>>runtime-checked conversion not a debug statement. If you cannot
>>adequately path test the code, then assume the worst. numeric_cast in
>>its current form is the correct tool for the job, from the sounds of it.
>I didn't say that it can't be tested. I said that it can't be easily unit

Well, I would put not being to automatically test something in that
category. In other words, how much confidence can you automate?

>If I'm doing a cast that should *never* fail then I don't want to
>throw. All that will do is bloat my exe with extra entries in the
>exception tables and screw over the optimizer.

In which case, I think the macro check I posted is the tool for the job,
and not a raw numeric_cast.

>>If you are doing GUI work I suspect that this would be one of those
>>'optimisations' that amounts to a drop in the ocean :->
>That's true here but I also sometimes use checked casts to convert from
>signed ints to unsigned ints when using STL. I'm sure that at least
>of these are more sensitive to performance. On compilers with
>zero-overhead exceptions there's another sort of overhead introduced by
>throw statements: each throw will add one(?) entry into the compiler's
>exception tables. These tables are not small (eg I just checked one of
>my apps built with CW 6 and 200K out of a 1.6M exe are exception
>Now these overheads aren't huge, but why should I pay *any* penalty for
>failure that should only happen via a programmer error?

You don't have to pay the penalty for a debug feature if you treat it as
a debug feature. That is what conditional compilation for. You can use
numeric_cast within this scenario, but numeric_cast's purpose in life is
not as a debug enabled/disabled feature but as an exception-throwing,
runtime-checked conversion.


  Kevlin Henney phone: +44 117 942 2990
  Curbralan Limited mobile: +44 7801 073 508
  mailto:kevlin_at_[hidden] fax: +44 870 052 2289

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