On Thu, Oct 01, 2009 at 10:10:13AM -0700, Sean Hefty wrote:
> >I've always felt the warning on implicit cast from larger to smaller
> >type to be somewhat useless - that is an unavoidable operation when
> >working with networking. Adding casts does nothing to actually improve
> >the code, and trying to change to smaller types results in worse code
> >gen and no improvement in function.
> 
> An explicit cast lets someone reading the code know that the
> original programmer was aware that data could be loss, or that data
> loss wouldn't occur because of the range of the data.  IMO, adding
> explicit casts to the code is better than having an equally number
> of implicit casts.

So for every cast your patches add you generate a rigorous proof that
the surrounding usage of those variables is correct and meets the
constraint? :)

All you really get is an annotation that there is a cast here. You
don't know what the type of operand is, you don't know if it is
an important cast, you don't know the type of the assignment
target. The explicit cast actually creats more questions, like, is
this truncating by design or because something got flubbed?

But the reader already knows that there is an implicit cast there -
this is C, all assignments can perform an implicit cast. A C
programmer must be aware of this and must know the types of all the
variables to correctly understand the code.

The biggest problem is that the cast is only correct if the types
never change. If someone changes the type then every instance of every
cast must be tracked down and fixed too. This is a huge maintenance
burden that implict casting avoids.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to