Help with casts

Doug Gwyn gwyn at smoke.brl.mil
Fri Feb 22 08:02:14 AEST 1991


In article <1991Feb21.040145.8678 at cec1.wustl.edu> abed at saturn.wustl.edu (Abed M. Hammoud) writes:
>	i.e my question is when I precede a variable by a cast does
>	that add to the amount of work done during run-time ?.

It might or might not, depending.  Note that the right way to express
what you are contemplating is "applying a cast", or "converting to a
different type", i.e. a more active notion of what a cast means.  In
some circumstances the compiler may have had to perform the conversion
anyway, so an explicit conversion might not add any burden.  There are
also some short cuts that are permitted that in some cases could avoid
having to "really" do the indicated conversion.  My recommendation is
to EITHER explicitly cast only where necessary to meet strict typing
requirements, OR explicitly cast in those circumstances and also every
place that the compiler would otherwise perform an implicit conversion.
The latter policy is rather hard for anyone other than a C "language
lawyer" to get right, so your best bet is to keep casts to a minimum.
In many cases, if a cast is actually necessary it indicates an improper
choice of types has been made somewhere.



More information about the Comp.lang.c mailing list