> Somewhat obviously, in writing drivers (e.g., VGA), one wishes to
> employ unsigned types -- 8-bit and 16-bit for "data," and (at least)
> 32-bit for addresses.

Why do you care about the sign of these types?  Java is nice enough
that all of the primitives types have fixed sizes.  ints are 32 bits,
shorts and bytes are exactly what you'd expect, etc.  There are
exactly three places where you will run into problems treating
unsigned values as signed values, I don't think any of them are common 
enough to be a real problem.  (All the common operations: like adding 1;
and clearing and setting bits just work.)

First is sign extension. This only happens when casting from a small
size to a larger bit width.  Using masks prevents the problem:
        int x = (int)byteVal & 0xFF;

Second is comparisons.  Comparing unsigned quantities via unsigned
operators may not always give you what you want.  How often does that
happen in a driver anyway?  Casting (without sign extension) to a
larger type will work, though.

Third problem is printing the number on the screen.  Thankfully we
have Integer.toHexString(x).

Certainly, this isn't nearly as clean as having real support in the
language for signed vs. unsigned types, but its quite workable. (Of
course, that invites its own host of problems.)

-Pat

----- ----- ---- ---  ---  --   -    -      -         -               -
Pat Tullmann                                       [EMAIL PROTECTED]
          This signature witticism intentionally left blank.

_______________________________________________
Kernel maillist  -  [EMAIL PROTECTED]
http://jos.org/mailman/listinfo/kernel

Reply via email to