size_t + ptrdiff_t

James Miller james at
Mon Feb 20 19:12:31 PST 2012

On 21 February 2012 12:22, Walter Bright <newshound2 at> wrote:
> On 2/20/2012 3:28 AM, Manu wrote:
>> Even size_t is often
>> broken in C. I have worked on 64bit systems with 32bit pointers where
>> size_t was
>> still 64bit, but ptrdiff_t was 32bit (I think PS3 is like this, but maybe
>> my
>> memory fails me)
> I don't know how that could be considered C standard compliant.
>> I want to be confident when I declare a numeric type that can interact
>> with
>> pointers, and also when I want the native type.
> I think you're probably best off for now by doing your own alias for it.

I don't know much about what is considered 'standard C', non x86
platforms or the intricacies of native types, so I would like some
clarification on the argument going on here.

AFAICT, The problem is that size_t is assumed to be the both the size
of the pointer and the size of the native int, but sometimes the
native int isn't the same as the size of the pointer? So you can have
64bit native ints and 32bit pointers (and maybe even vice-versa)?

I also saw reference to register sizes, which I assumed, but am now
guessing to be wrong, were the same size as pointers. So the problem
seems to be that there are the following things that are all different

 * fixed int (32 bit)
 * native int
 * pointer
 * register

But some types are conflating them?

The argument seems to be confusing me because it jumps rapidly from
talking about different processors to different OSes to the C

If the only problem is that we need some more types, can't we add them
in? I don't see the problem with having verbose, import-only names for
things outside the norm, alias them if you want, longer names are
better for newcomers. For example, what is ptrdiff_t? I have never
seen that before, and the name doesn't help me, from the alias in
druntime, it seems to be the type that represents the difference
between 2 pointers. Help me out here, what on earth would I use that

(On a side note to that, no way is ssize_t a good name, ever, forwards
and backwards, what on earth is it? super-size_t? here to save you?
shady-size_t? you have to make sure it doesn't sell you drugs?
size-size_t? it has a stammer?)

I also saw a lot of talk about C compilers that don't do the right
thing, is that relevant? (I mean that sincerely, not criticism)

More information about the Digitalmars-d mailing list