← Back to team overview

cuneiform team mailing list archive

Re: Type casts

 

On Mon, Dec 8, 2008 at 3:50 PM, Yury V. Zaytsev <yury@xxxxxxxxxx> wrote:

> I wonder why things like static_cast<int>(double) are never used in the
> code e.g. when a float value is converted to int? Is it because it's too
> much work to refactor the old code so you force the compiler to hide the
> warnings concerning this subject or there is some other reason?

I think that most of the code predates proper C++ casting rules. The
build system should not hide these unless you specifically tell it to.
If it does, then I would call it a bug. Getting rid of them is one of
the eventual goals, but just blindly adding casts everywhere can lead
to subtle bugs in some vague and rare circumstances.

Is there any reason why you should use static_cast<int>(double) rather
than the plain C cast (int) double? The latter is a lot nicer looking
(to me anyway) and there can never be casting errors because the
arguments are not objects.



References