After many years programming in C language, I'm always unsure if it is
safer to use signed int or unsigned int.
Of course there are situations where signed or unsigned is clearly
better. For example, if the values could assume negative values,
signed int is the only solution. If you are manipulating single bits
(&, |, ^, <<, >>), unsigned ints are your friends.
What about other situations? For example, what do you use for the "i"
loop variable?
I recently activated gcc -Wsign-conversion option on a codebase and
received a lot of warnings. I started to fix them, usually expliciting casting. Is it the way or is it better to avoid the warning from the beginning, choosing the right signed or unsigned type?
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,090 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 45:19:02 |
| Calls: | 13,946 |
| Calls today: | 3 |
| Files: | 187,034 |
| D/L today: |
8,061 files (2,942M bytes) |
| Messages: | 2,460,944 |