
On Tue, Jun 15, 2010 at 10:03 AM, Steven Watanabe <watanabesj@gmail.com> wrote:
Humph. Has anyone in this discussion actually looked at the code in question? a) There can be no overflow because the possible values are enumerated. b) With the current code, the compiler will implicitly use a static_cast.
With the current code, the compiler will use an implicit conversion which is not the same as static_cast in general. Casts are designed to punch holes in the C/C++ type system, which by definition is a dangerous thing to do. In contrast, one has to assume that implicit conversions are a necessary, reasonably safe part of the language. Integer implicit conversions specifically are very common in C and C++. For example, incrementing a short int results in two implicit conversions, one of which might lead to truncating the value. That is about as safe (or unsafe) as the code in question, so why nobody cares about that case? Answer: because the compiler doesn't warn. If you don't want your compiler to issue a particular warning, a type cast should be the last solution to reach for, IMO. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode