| ▲ | throwaway894345 13 hours ago | ||||||||||||||||||||||
That’s definitely not true. Unsigned ints have no “negativity” semantic. Wrapping around is what happens when you decrement the minimum value of any integer type, including signed types. Regardless of the type you use to represent an integer value that cannot legally be negative, you will have to take care not to allow your program to return values lower than zero for things like indices or sizes. | |||||||||||||||||||||||
| ▲ | oasisaimlessly 13 hours ago | parent | next [-] | ||||||||||||||||||||||
> Wrapping around is what happens when you decrement the minimum value of any integer type, including signed types. No, signed wraparound is undefined behavior in C, whereas unsigneds are defined to wraparound. If you use -ftrapv, signed wraparound is an immediate abort(). | |||||||||||||||||||||||
| |||||||||||||||||||||||
| ▲ | einpoklum 10 hours ago | parent | prev [-] | ||||||||||||||||||||||
> Unsigned ints have no “negativity” semantic. They do. The code:
is well-defined in C and C++. See this discussion on StackOverflow for spec text and reference: | |||||||||||||||||||||||
| |||||||||||||||||||||||