Support for unsigned integers

In response to the post

http://yorick.sourceforge.net/phpBB2/viewtopic.php?t=249 I have added support for unsigned integers with the file i/unsigned.i. The functions are autoloaded. They are:

Six comparison functions: u_gt(x,y), u_lt(x,y), u_ge(x,y), u_le(x,y), u_eq(x,y), u_ne(x,y)

Three arithmetic functions: u_shr(x,n), u_div(x,y), u_mod(x,y)

Two explicit cast functions: u_cast(x,type), s_char(x)

Note that u_div and u_mod accept a third argument as output, so that a single call can return both quotient and remainder.

A large fraction of the uses of unsigned types in C and C++ are incorrect uses of these types as assertions that the value cannot be negative. This usage is incorrect, because no such assertion can be verified -- in fact, no bit pattern represents a negative value, so such an assertion is meaningless.

The harm comes from the fact that signed values are implicitly cast to unsigned values whenever they occur together in an algebraic expression. Division or modulo operations then do not do what you expect, a bug which is difficult to see.

The only correct uses of unsigned types are (1) when you explicitly want all operations involving them to be the unsigned operations, or (2) when you know that the values are non-negative AND that you need the final factor of two in range.

In yorick, the overhead of so many additional primitive data types is (in my judgment) too high, so the support in unsigned.i is to provide as functions all of the operations which differ between signed and unsigned types. The comment at the top of unsigned.i also has advice for what to do about printing unsigned values, which still has no direct support.

Feel free to post disagreements with this position as replies to this announcement.