When to use unsigned values over signed ones?

I was glad to find a good conversation on this subject, as I hadn’t really given it much thought before.

In summary, signed is a good general choice – even when you’re dead sure all the numbers are positive – if you’re going to do arithmetic on the variable (like in a typical for loop case).

unsigned starts to make more sense when:

  • You’re going to do bitwise things like masks, or
  • You’re desperate to to take advantage of the sign bit for that extra positive range .

Personally, I like signed because I don’t trust myself to stay consistent and avoid mixing the two types (like the article warns against).

Leave a Comment