Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!news.cs.indiana.edu!arizona.edu!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: The use of unsigned int Keywords: unsigned int, C Message-ID: <819@caslon.cs.arizona.edu> Date: 9 Feb 91 01:30:23 GMT References: <1255@tredysvr.Tredydev.Unisys.COM> Organization: U of Arizona CS Dept, Tucson Lines: 26 In article <1255@tredysvr.Tredydev.Unisys.COM> paul@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@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@cs.arizona.edu | carton and subsequent injury to the user.