[LC++]int versus unsigned int

Jack Lloyd lloyd at acm.jhu.edu
Thu Sep 27 02:44:05 UTC 2001


> My default behavior is to use an int except when:
>    a)  you need the extra large values
>    b)  you are working with bit arrays or other packed data structures
>    b)  you specifically need a short or long because of hardware or other issues

It's also useful to consider if the negative value ever makes sense. If I'm
specifying a length, a negative value isn't useful, so I might as well use
an unsigned int so people can pass in a whole ton of data if they feel like
it (how often people will want to pass more than 2 gigs of data into a
function at once is debatable, but whatever). The typing rules for ints are
pretty useless, but at least they can give someone using the code a hint
that they shouldn't do something stupid. -J




More information about the tuxCPProgramming mailing list