On Jan 13, 2011, at 10:21 PM, Nathan Blackham wrote:
>> Without an explicit cast, shouldn't that be fatal? As you say, it
>> isn't. On Ubuntu, even with gcc -Wall, I get no warning.
>
> I would expect it to be fatal as well.  I am surprised that it isn't.

It's not fatal because it's an implicit cast. Number conversion is
usually considered implicit in C++. The compiler may warn about the
loss of precision (in g++'s case it allows you to do that with
-Wconversion), but it should never be fatal.

On Fri, Jan 14, 2011 at 07:37, Dave Smith <[email protected]> wrote:
>
> The double is floored to the closest int, unless it's too large to fit. So, 
> yes, it's dangerous. That's why I want the warning on all distros! C++ is too 
> dangerous for the compiler to let this kind of code through without a mention.

-Wconversion was specifically built for this purpose. I'm sorry the
libraries your are incorporating into your project cause problems with
this, but that's their problem, not g++. There must be enough
developers using g++ (or at least contributing to g++) that feel like
the conversion is more of a feature than a danger. Otherwise, the
-Wconversion would be on by default or included in -Wall.

I personally like it the way it is. Implicit conversion is fairly
normal from the kernel projects I've worked on. If you really want to
be a stickler though and don't like -Wconversion, c++ offers explicit
casting. This will usually signify to someone whose looking at your
code that you are doing some magic.

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to