Re: Does Casting Slow a Program Down?



On Jan 31, 10:01 am, Zara <me_z...@xxxxxxxxxxxxxxx> wrote:

If the compiler detectes tha usLimit and iLimit are constants, then it
may detect that (int)usLimit is also constant and it would probably
generate the exact same machine code for both samples.

But this behaviour depends on the optimizations capabilities an
settings of the compiler, and of the code surrounding the snippet you
have shown us.

You may help the compiler declaring either
const unsigned short usLimit=10;
or
const int iLimit=10;

Thanks very much for your fast reply. I was thinking in general
terms. usLimit/iLimit are given a constant value in the example that
I posted but I was thinking in terms of their being variables that are
determined by input data and/or passed as arguments to a function.
Also, what about casting a (single precision) float to a double or
vice versa? Would that impact the run time or would it depend on the
compiler?

Thanks again,
Peter.

.



Relevant Pages

  • Re: Does Casting Slow a Program Down?
    ... If the compiler detectes tha usLimit and iLimit are constants, ... But this behaviour depends on the optimizations capabilities an ... Casting is an operation in C. ...
    (comp.lang.c)
  • Re: How do I dig a memory value out?
    ... The only C compiler I could find at the time was ... The Atari keyboard was missing several characters, ... higher level language plus a few common data types ... hand tweeked machine code was entered directly in the ...
    (microsoft.public.vb.general.discussion)
  • Re: Basic compiler
    ... stand-alone executables in machine code were the "Einstein Compiler" ... and Microsoft's TASC (The AppleSoft Compiler). ...
    (comp.sys.apple2)
  • Re: Can read all data off file accurately with fstream
    ... is an invalid character for a floating point value), ... which the compiler I used ... Ensure that you *know* their exact content. ... on to things like random inputs. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Can read all data off file accurately with fstream
    ... is an invalid character for a floating point value), ... which the compiler I used ... Ensure that you *know* their exact content. ... on to things like random inputs. ...
    (comp.lang.cpp)