Re: Does Casting Slow a Program Down?
- From: rpbg123@xxxxxxxxx (Roland Pibinger)
- Date: Wed, 31 Jan 2007 19:11:59 GMT
On Wed, 31 Jan 2007 15:04:29 +0000, Chris Dollin <chris.dollin@xxxxxx>
wrote:
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;
}
It might, but it would have nothing to do with the casts,
since they're both unnecessary -- `usLimit` is
converted from `unsigned short` to `int` regardless.
Right, 'unsigned short' is prometed to 'int' anyway. The casts are
probably in the code because the compiler (hopefully) issues a warning
otherwise. So the real question is whether it makes sense to use
'unsigned short' instead of 'int' in this case.
Best regards,
Roland Pibinger
.
- References:
- Does Casting Slow a Program Down?
- From: PeterOut
- Re: Does Casting Slow a Program Down?
- From: Chris Dollin
- Does Casting Slow a Program Down?
- Prev by Date: Re: How to improve this sort?
- Next by Date: Re: C bit twidders ... I'm in need of a dose of clever.
- Previous by thread: Re: Does Casting Slow a Program Down?
- Next by thread: Re: Does Casting Slow a Program Down?
- Index(es):
Relevant Pages
|