Quote Originally Posted by grumpy
The (T) conversion syntax is still supported by C++. This is one case where either form can be used. It is therefore up to the programmer to exercise the old brain box and decide which form of cast to use. In practice, casting a double to a float is safe (except for loss of precision and loss of range), so there is little or no real benefit to using static_cast to do the conversion.
Sure there is. First, you avoid the outdated and hard-to-find C syntax. Suppose you later change y to be a double. You need to remove all the conversions. Which is easier to grep for, static_cast or ()?
Second, static_cast only permits safe casts, while the C cast permits everything. In other words, if you make some mistake, the static_cast is more likely to catch it.
OK, the above two are not that important in this case. (float) can be searched for rather easily, and there aren't many mistakes one can make here. (double->pointer, for example, is not a valid conversion even using C casts.) But:
Third, you probably have some other places in the program where you really should use C++ casts. A reinterpret_cast from a WinAPI datatype to a pointer, perhaps? A static_cast from int to char? (Slip and you've typed char* instead of char - not good.) Perhaps a dynamic_cast or two? Consistency is good, so all casts should be C++ if one is.
Fourth, you should make a habit out of not using C casts. It's the same reason as why I urge people to use for(int i = 0; i < end; ++i) instead of i++. Sure, no self-respecting compiler will make any difference between the two, but using prefix is a good habit when you switch to iterators. It also helps dispell the myth that using prefix increments in the loop updater causes the increment to be performed before the loop body runs.