3 ms·
> But if you do any sort of math on those sizes then you probably want them to be signed anyway to avoid -1 rolling over to UINT_MAX and bugging out your system
by masklinn 4y ago
> But if you do any sort of math on those sizes then you probably want them to be signed anyway to avoid -1 rolling over to UINT_MAX and bugging out your system.
Both are shit and will create bugs if you let them through, doesn't make much a difference.
In fact there are languages which allow negative indices, in which going to -1 is a lot worse, because that's a valid index, just a nonsensical one.
> Automatic signed to unsigned type coercion is extremely bug prone, so better avoid using unsigned integers entirely unless you never want to use them in math formulas
Or you can just not have "automatic signed to unsigned type coercion" in the first place. Or any sort of automatic coercion for that matter.
> You avoid many more bugs by limiting collections to 2 billion than by mixing signed and unsigned integers.
Hell you'd avoid many more bugs by limiting collections to 32000 too!
> I have had a lot of bugs related to unsigned to signed casts.
I've had a lot of bugs related to signed to signed casts.
That doesn't say anything about signed values, that says something about casts.