News for hackers. Stuff that matters.
Re:Should I Use Signed or Unsigned Ints? by ridiculous_fish on Saturday August 01, 2015 @05:56PM (#9988840)
This is good general advice.

A key difference is whether the type is meant to be an index (counting) or for arithmetic. Indexing with unsigned integers certainly has its pitfalls:

    while (idx >= 0) { foo(arr[idx]); idx--; }
But this is outweighed by the enormous and under-appreciated dangers of signed arithmetic!

Try writing C functions add, subtract, multiply, and divide, that do anything on overflow except UB. It's trivial with unsigned, but wretched and horrible with signed types. And real software like PostgreSQL gets it wrong, with crashy consequences: http://kqueue.org/blog/2012/12/31/idiv-dos/#sql

Re:Should I Use Signed or Unsigned Ints? by nly on Saturday August 01, 2015 @07:34PM (#9989137)
> Try writing C functions add, subtract, multiply, and divide, that do anything on overflow except UB.

For those curious...

https://www.securecoding.cert.org/confluence/display/c/INT32...

Re:Should I Use Signed or Unsigned Ints? by revelation on Saturday August 01, 2015 @06:40PM (#9988990)
Well, there are builtin functions that do this safely for signed integers.

Of course that means you need to be aware which calculations are potentially dangerous, you need to know about signed integer overflow problems in the first place, etc. ..

Re:Should I Use Signed or Unsigned Ints? by michaelhoffman on Saturday August 01, 2015 @11:23PM (#9989616)
What functions are those?
Re:Should I Use Signed or Unsigned Ints? by kevinnk on Sunday August 02, 2015 @12:42AM (#9989775)
Re:Should I Use Signed or Unsigned Ints? by jchomali on Saturday August 01, 2015 @07:08PM (#9989065)
I totally agree.