The use of unsigned int

Walter Bright bright at nazgul.UUCP
Tue Feb 26 05:16:59 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?

If the values for your variables are never negative, you should declare them
as unsigned. The reasons are:
1.	Documentation
2.	Aid to the optimizer. Certain optimizations are not possible if the
	variable could be negative, such as replacing a divide with a shift
	and replacing a loop index with a pointer.



More information about the Comp.lang.c mailing list