News for hackers. Stuff that matters.
Re:Pitfalls in C and C++: Unsigned Types (2011) by dllthomas on Wednesday September 25, 2013 @03:10PM (#6446624)
Sure. Of course, at the same time sometimes overflow and undeflow is fine and should be ignored (when treating unsigned ints as the modular ring they actually are). This is of course not a criticism of CL, which I understand does not check these by default and so is clearly capable of not checking - just a note to anyone who might take more from your comment than was there.
Re:Pitfalls in C and C++: Unsigned Types (2011) by betterunix on Wednesday September 25, 2013 @05:06PM (#6447288)
Actually, CL goes a step further, which I like: by default, integer arithmetic is arbitrary precision. There are no overflows, unless you count running out of RAM to store your numbers as an overflow. Modular arithmetic must be explicitly specified, leaving no room for surprises:

  (mod (+ x y) N)
The reason I prefer this behavior to C's is that it is more natural. Most of the time when we think of integer arithmetic, we do not assume that it is modulo N; we assume things like " x - 1 < x " will always be true. Forcing unexpected semantics on programmers is a recipe for bugs, and integer underflow/overflow bugs are not uncommon in C programs.
Re:Pitfalls in C and C++: Unsigned Types (2011) by dllthomas on Wednesday September 25, 2013 @05:13PM (#6447327)
I think that'd probably be inappropriate for C's use cases, but I think generally it's a good move. I do like encoding the modular behavior in the type, FWIW; specifying a mod manually everywhere it goes leads to unreadable code. I agree, however, that it should probably not be the default type.
Re:Pitfalls in C and C++: Unsigned Types (2011) by betterunix on Wednesday September 25, 2013 @04:39PM (#6447146)
The way I see it, if you want arithmetic modulo N, you should be explicit. For example, in CL:

[Edit: Just noticed this got posted, but someone replied. The correct version of this is above.]

Re:Pitfalls in C and C++: Unsigned Types (2011) by dllthomas on Wednesday September 25, 2013 @04:42PM (#6447159)
Sure, I don't disagree. I'm just saying that's a legitimate use case that should be supported somehow.