C++ interop - what to do about long and unsigned long?

monarch_dodra via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 11 00:35:18 PDT 2014


On Wednesday, 10 September 2014 at 20:41:45 UTC, Walter Bright 
wrote:
> C++'s long and unsigned long can be accessed with c_long and 
> c_ulong. Unfortunately, these are aliases and mangle to their 
> underlying types.
>
> Meaning that there is no way to interface to a C++ function 
> declared as:
>
>     void foo(unsigned long);
>
> So, what to do about this?
>
> 1. elevate c_long and c_ulong into full fledged types.
>
> 2. create full fledged types __c_long and __c_ulong, and alias 
> c_long and c_ulong to them.

Having actual new types makes me a bit nervous in regards to how 
overloads will be handled, and how templates will be instantiated.

I don't know how things happen behind the scenes, but (as I 
remember), writing "portable" C++ code to handle all possible 
integral primitives was a real hell, as on some systems, 
"foo(int)/foo(long)" would collide, whereas on others, you *need* 
both declared.

Will this start happening in D too now...?


More information about the Digitalmars-d mailing list