News for hackers. Stuff that matters.
Re:Almost Always Unsigned by quelsolaar on Sunday January 02, 2022 @05:36AM (#29767564)
Interesting perspective. I dont have the same experience. To me a wraping 32 bit index on a 64bit machine is much more likely to seg fault if it reads 4 billion values forward, rather than a few bytes backwards and therefore i find unsigned index wrapps to be easier to debug. In all fairness wrapping indicies are an extremely rare bug for me, so i cant say i have much experience debugging it.
Re:Almost Always Unsigned by eterevsky on Sunday January 02, 2022 @07:38AM (#29768237)
I think when you use a variable that can have values in the range of millions, it's prudent to use 64-bit types and not 32-bit unless you are very much memory-constrained. And I've never seen a 64-bit signed variable overflow.
Re:Almost Always Unsigned by jcelerier on Sunday January 02, 2022 @05:48AM (#29767639)
> In all fairness wrapping indicies are an extremely rare bug for me, so i cant say i have much experience debugging it.

Do you run your code with -fsanitize=undefined -fsanitize=integer ?

Re:Almost Always Unsigned by quelsolaar on Sunday January 02, 2022 @09:59AM (#29769198)
No I do not. I run ISO conformant C without options.
Re:Almost Always Unsigned by jcelerier on Sunday January 02, 2022 @10:32AM (#29769476)
You really should try it on your codebase if you have the occasion