C style type casting impact on program perf.


Hi,

I am wondering if a C style type casting has an impact on program performance or anything?

I know casting is done at compile time and thus it should not have any impact, but I am looking for more info on this.

Thank you for your help.
For basic types, not unless you're converting between integer and floating point types, which are relatively expensive operations.
For complex types, a cast is either invalid, or involves a function call to the conversion operator overload. For a valid cast performed with the syntax T(x) rather than (T)x, a constructor is called.
Sorry, I should have given an example. Here it is,

float f;
f = 3.0;

int i; i = (int) f;

How does this impacts the program performance? Does it?

Thanks, Bojan
Yes, it does.
Hi ,
how do we decide which cast is optimize the performance , is there any thumb rule ?
There's no difference for basic types.
For complex types, it depends on the implementations of the various functions. For example, for an x of type R, in principle the implementations of T::T(const R &) and R::operator T() could differ significantly such that T(x) and (T)x take very different amounts of time, but this would be rare in practice.
thanks helios .. that is the thing to remember . thanks a lot
Topic archived. No new replies allowed.