size_t + ptrdiff_t

Juan Manuel Cabo juanmanuel.cabo at
Tue Feb 21 14:45:37 PST 2012

> c_long and c_ulong are guaranteed to match target long size (here
> would also go c_int and c_uint ;-).

That is so good! Thanks!

Currently, htod translates "unsigned long" to uint, which is wrong
in linux 64 bits. Translating to size_t fixes that for linux, but
I fear that a C "unsigned long" is not 64bit in all 64bit systems

    "About size_t and ptrdiff_t"

Ran into this problem with mysql.h:

	typedef st_mysql_field {
            unsigned long length;
            unsigned long max_length;
            unsigned int name_length;

The only adequate fix, is your c_long that matches C's long.

This is because uint doesn't change when in 64bit, and size_t
fixes it for linux but maybe not for windows.

The C standard only guarantees that:

  sizeof(char) <= sizeof(int) <= sizeof(long) <= sizeof(size_t)

Which is insane. At some point in history, a C int meant the
native register size for fast integer operations. But now C int
seems to have been frozen to 32bits to avoid struct hell.

So, in conclusion, my opinion is that there is no sane way
of mapping C types to D types but to use something like your
c_int, c_uint, c_long, c_ulong. Otherwise, the insanity
of non-standard sizes and portability never stops.

Love the intptr_t!

A REQUEST: how about adding a c_size_t too?


More information about the Digitalmars-d mailing list