Shouldn't c_long and c_ulong be library typedefs?

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Sep 5 16:52:01 PDT 2012


I'm interfacing with C++ and found a little overload problem:

C++:
void test(unsigned int x)  { }
void test(unsigned long x) { }

int main()
{
    unsigned int x;
    unsigned long y;
    test(x);
    test(y);
    return 0;
}

No problem, but in D:

import core.stdc.config;
void test(uint x)  { }
void test(c_ulong x) { }

void main()
{
    uint x;
    c_ulong y;
    test(x);
    test(y);
}

test.d(12): Error: function test.test called with argument types:
	((uint))
matches both:
	test.test(uint x)
and:
	test.test(uint x)

c_ulong is an alias to either uint or ulong based on the architecture.
But it is an *alias*, meaning you can't overload it like the above
based on the architecture. This leads to cases where compiling on one
architecture works (x64 -> c_ulong is D ulong, overloads with uint)
but on another one it doesn't (x32 -> c_ulong is D uint, can't
overload with uint).

Anyway I've two questions:
1) Has anyone come up with a library solution for a typedef because I
need it for cases like these, and
2) Will c_long/c_ulong be converted to a library typedef or will they
remain aliases?


More information about the Digitalmars-d mailing list