Why prefer signed over unsigned in C++? [closed]

As per requests in comments: I prefer int instead of unsigned because…

  1. it’s shorter (I’m serious!)

  2. it’s more generic and more intuitive (i. e. I like to be able to assume that 1 - 2 is -1 and not some obscure huge number)

  3. what if I want to signal an error by returning an out-of-range value?

Of course there are counter-arguments, but these are the principal reasons I like to declare my integers as int instead of unsigned. Of course, this is not always true, in other cases, an unsigned is just a better tool for a task, I am just answering the “why would anyone prefer defaulting to signed” question specifically.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)