Re: Does Casting Slow a Program Down?



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
.



Relevant Pages

  • Re: Stuffing LSBs of long into unsigned short
    ... > short int. ... The rule for converting a positive value, to an unsigned short value, ... regardless of the representation of negative values. ...
    (comp.lang.c)
  • Re: Generalized function for deallocating and setting pointer to NULL
    ... pointer value is set to NULL, and if it isn't, of deallocating ... and setting it's value to NULL regardless of the pointer's type. ... How would I pass an int* to this function and ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.lang.c)
  • Re: [patch 7/8] fdmap v2 - implement sys_socket2
    ... Program Thread: Library Thread: ... int x = FD_CLOEXEC; ... BTW, regardless of anything else, in such situation this "library ...
    (Linux-Kernel)
  • Re: Pointer to int, implicit conversion
    ... regardless of the type of the expression int. ... So basically, the conditionals take the value, regardless of its ... type, and return false if it's zero, otherwise ...
    (comp.lang.c)
  • Re: Is this doable in MS C?
    ... Your code uses va_arg(argptr, void*) for all arguments, ... regardless of their type. ... But with 64-bit MSVC compiler, ... When you do printf("%d", 1), an int is placed ...
    (microsoft.public.vc.language)