The use of unsigned int
Dave P. Schaumann
dave at cs.arizona.edu
Sat Feb 9 12:30:23 AEST 1991
In article <1255 at tredysvr.Tredydev.Unisys.COM> paul at tredysvr.Tredydev.Unisys.COM (Paul Siu) writes:
>The most commonly use, and commonly returned type in C is probably int.
>In some cases, wouldn't it be more appropriate if unsigned int was used
>instead, such as when you are indexing an array, or returning a length?
>
>I heard that int is usually declared as the most efficent type in C, would
>using unsigned int cause any problems such as slow things down or cause
>type-conversation problems?
There is no general answer to this question. On a twos-complement machine,
the instructions generated for int/unsigned int (of the same size) should
be virtually identical. The only differences would be in checking for overflow
and checking for sequence (ie less/greater). Even here, I would expect the
differences in instruction execution speed would be very small, if not 0.
I've never written assembly code on a sign/magnatude machine, so I don't know
about those. (Are there any 1's complement machines out there?)
>Paul Siu
>paul at tredysvr.tredydev.unisys.com
--
Dave Schaumann | DANGER: Access hole may tear easily. Use of the access
| holes for lifting or carrying may result in damage to the
dave at cs.arizona.edu | carton and subsequent injury to the user.
More information about the Comp.lang.c
mailing list