Re: Does Casting Slow a Program Down?
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 31 Jan 2007 07:07:47 -0800
PeterOut wrote:
If I had code like this.
unsigned short usLimit=10
int a[10], i;
for (i=0; i<(int)usLimit; ++i)
{
a[i]=(int)usLimit;
}
would it run slower than this?
int a[10], i, iLimit=10;
for (i=0; i<iLimit; ++i)
{
a[i]=iLimit;
}
Quality of code generation is implementation defined. A good optimiser
might be able to figure out that usLimit is not changed and hence, use
a single, cached value. On some hardware, short and int might be of
the same size and representation. In such cases, the cast never takes
up any object code. But speed of execution is not specified by the
standard and no guarantees are made. An assignent statement that takes
ten days to complete is perfectly legal, as per the standard, as long
as all the side effects are resolved before the next sequence point.
.
- Follow-Ups:
- Re: Does Casting Slow a Program Down?
- From: Serve Laurijssen
- Re: Does Casting Slow a Program Down?
- References:
- Does Casting Slow a Program Down?
- From: PeterOut
- Does Casting Slow a Program Down?
- Prev by Date: Re: Does Casting Slow a Program Down?
- Next by Date: Re: Does Casting Slow a Program Down?
- Previous by thread: Re: Does Casting Slow a Program Down?
- Next by thread: Re: Does Casting Slow a Program Down?
- Index(es):
Relevant Pages
|