[M3devel] unsigned integers?

Jay jayk123 at hotmail.com
Mon Jun 2 23:07:22 CEST 2008

What is the status and chance of a 32 bit integer with the range 0..0xFFFFFFFF and of a 64 bit integer type with range 0 .. 0xFFFFFFFFFFFFFFFF?
Already available?
Impossible to provide?Only available in unsafe modules?Only available with restricted operations in safe modules, and more operations in unsafe modules?
Specifically, I think looping from 0 to N is safe -- no overflow.
Subtracting a CARDINAL from an "UNSIGNED" is safe -- cannot overflow.
Adding "UNSIGNED" to "UNSIGNED" is not safe -- can overflow.
Adding or subtracting an INTEGER to "UNSIGNED" is not safe.
Subtracting "UNSIGNED" from "UNSIGNED" is not safe -- can overflow.Comparing UNSIGNED to UNSIGNED for any of =, <, >, !=, is safe.
Comparing UNSIGNED to CARDINAL or INTEGER is safe, but must be done carefully.
  Specifically, UNSIGNED > LAST(CARDINAL) is not equal to any CARDINAL or UNSIGNED.The unsafe operations above could be runtime checked perhaps.
  I guess that's a different larger point/dilemna -- when to allow potentially unsafe operations but with runtime checks vs. the compiler just disallowing them entirely. e.g. adding an integer to an integer is not even safe, but checked maybe at runtime (ok, at least assignment to subrange types is checked). Yes, I know I know, the runtime checks on at least many integer operations is yet lacking.
Is there any, um, value in such a type?
Is it just me blindly trying to cast Modula-3 as C (yes), but there's no actual value (uncertain)?
Btw, I agree there's no point in this type in representing file sizes or offsets. They should be at least 63 bit integers. One bit doesn't buy much for file sizes. It might be something for address spaces though?
It bugs me to define types like uintptr_t = CARDINAL or uintptr_t = INTEGER. It seems quite wrong.
Perhaps the unsigned types larger than 16 bits just should not be defined in Cstdint. ??
But there is already Ctypes.unsigned_int, unsigned_long_long, whose underlying type I think is signed, but which convention says you just don't do signed operations on, but which the compiler doesn't enforce, right?
You know, maybe Word.T should not be INTEGER but this mythological UNSIGNED/UINT??????
 - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080602/2494a7a1/attachment-0001.html>

More information about the M3devel mailing list