[M3devel] long vs. INTEGER? ranges vs. word/integer?

Peter Eiserloh eiserlohpp at yahoo.com
Sat Jan 3 13:50:53 CET 2009


Hi Jay,

Sorry, for not speaking up earlier, I have been lurking
for the last ten years.  The last thing that got me
really interested was the discussion about NEW() returning
either NULL, or a checked runtime exception on failure to 
allocate memory.

Okay, I wrote a test program.  You are right sizeof(long)
 == sizeof(long long) equals 8 bytes (64 bits).

So, I looked it up in the "C A Reference Manual" (CARM)
4th edition.  It has been over ten years since I last
looked at it.  I have been corrected and educated.

Sorry about discussing a foreign language, but ...

To quote from page 120 (5.3):

  The size of a pointer is implementation dependent and in
  some cases varies depending on the type of the object
  pointed to. For example, data pointers may be shorter or
  longer than function pointers (section 6.1.5).  There is
  not necessarily any relationship between pointer sizes 
  and the size of any integer type, although it is common
  to assume that type _long_ is at least as large as any
  pointer type.

Page 123 (5.3.3):
  1 - Pointers are often not the same size as _int_, and 
      sometimes not the same size as _long_.  Sometimes
      their size is a compiler option.
  2 - Character and void * pointers can be larger that
      other kinds of pointers, or may use a representation
      that is incompatible with other kinds of pointers.
  3 - Function pointers and data pointer may have
      significantly different representations, including
      different sizes.

Page 292 (11.1)
  Type _size_t_ is the unsigned integral type of the result
  of the sizeof operator -- probably _unsigned long_; pre-ISO
  implementations often use the (unsigned) type _int_ for 
  this purpose.

To paraphrase both Nelson (SPWM3) and Harbison (Modula-3).
When doing a LOOPHOLE(e,T), ensure that BITSIZE(e) equals
BITSIZE(T).

In addition, -(x,y : ADDRESS) : INTEGER
The SPWM3 does not have a LONGINT, but we now do as of 
a few months ago.

The above operation on addresses implies that the difference
between ANY two addresses can be represented in an INTEGER,
with the further implication that an ADDRESS can be
represented in an INTEGER (i.e., a size_t is an INTEGER).

[Roland] So MS-DOS used a size_t of 2, but void* was 4, wow,
that sure sounds broken.  64 KB is the maximum size of an
object in memory.  Thank god, we don't use MS-DOS anymore.


+--------------------------------------------------------+
| Peter P. Eiserloh                                      |
+--------------------------------------------------------+


      



More information about the M3devel mailing list