[MLton] Building MLton

Vesa Karvonen vesa.karvonen@cs.helsinki.fi
Mon, 4 Jul 2005 16:29:55 +0300

Quoting John Skaller <skaller@users.sourceforge.net>:
> I'm not sure, I think:  ptrdiff_t only has to be big enough to
> hold the signed difference between two pointers into
> the same object.

[which includes arrays]

> So it is perfectly feasible to have 64 bit addresses,
> but only 32 bit size_t and ptrdiff_t 
> .. as far as I can glean from the C99 Standard anyhow.

Yes. It is possible. It would mean, however, that arrays would
be limited to 2G elements in such a C implementation.

The main difference between size_t and unsigned long is that
unsigned long is guaranteed to be at least 32-bits, while size_t
is guaranteed to be able to hold the size of any object (including
arrays). Thus there is no dependency between the size of pointers
and the size of (unsigned) long, but there is a dependency between
size_t (and ptrdiff_t) and the size of pointers.

In summary, if you want to manipulate array (object) indices and
sizes, you should be using ptrdiff_t and size_t. If you want to
manipulate exactly 64-bit integers, you should be using int64_t
and uint64_t (although it is possible that a C implementation does
not have exactly 64-bit integers). If you want to manipulate at
least 64-bit integers you should be using (unsigned) long long int.
(These apply to C99.)

-Vesa Karvonen