I'd like to understand better why choose
Let me paraphrase the video, as the experts said it succinctly.
- No simple guideline.
- In systems programming, we need integers of different sizes and signedness.
- Many conversions and arcane rules govern arithmetic (like for
auto), so we need to be careful.
- Here's some simple guidelines:
- Use signed integers unless you need two's complement arithmetic or a bit pattern
- Use the smallest integer that will suffice.
- Otherwise, use
intif you think you could count the items, and a 64-bit integer if it's even more than you would want to count.
- Stop worrying and use tools to tell you when you need a different type or size.
intuntil you have a reason not to.
- Use unsigned only for bit patterns.
- Never mix signed and unsigned
Wariness about signedness rules aside, my one-sentence take away from the experts:
Use the appropriate type, and when you don't know, use an
intuntil you do know.