Shouldn't c_long and c_ulong be library typedefs?
Mehrdad
wfunction at hotmail.com
Wed Sep 5 20:33:54 PDT 2012
On Wednesday, 5 September 2012 at 23:51:41 UTC, Andrej Mitrovic
wrote:
> 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?
I was complaining about something similar way back when (I was
saying size_t should not be the same data type as uint) but the
idea got thrown in the trash.
More information about the Digitalmars-d
mailing list