Thomas Hruska <[EMAIL PROTECTED]> wrote: > Mohan S N wrote: > > > Ananth wrote: > > > > Simple thumb of rule I've always followed: > > > > (1) Cast all variables in a statement to same type > > > > why why why? > > Well, the the main reason do that is because it forces the > compiler to do what the developer wants it to do not what the > compiler thinks it should do.
That may be the main excuse, but it's not a good reason. In general, there's no reason to use a cast to bring operands to the same type. Both C and C++ have integral promotions and usual arithmetic conversions for that. If a compiler produces 0 instead of 0.5 for the expression 1/2 then there's a problem with the programmer, not the compiler. There's only one cure for that... education. -- Peter
