C++ / const class pointer signature / unable to find correct D syntax

Uknown sireeshkodali1 at gmail.com
Fri May 4 07:57:26 UTC 2018


On Friday, 4 May 2018 at 07:49:02 UTC, Robert M. Münch wrote:
> I have a static C++ and can't make it to get a correct binding 
> for one function:
>
> DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class 
> b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
> __ptr64 const) __ptr64
> LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class 
> b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
> __ptr64) __ptr64
>
> So I somehow get some more const from D. This is the code I 
> used:
>
>    final uint _begin(ref Image image, const(InitParams) 
> initParams);
>
> Which creates a const pointer to a const class signature. But 
> it should only be a const pointer. Any idea how to solve this?

The problem is that const in D is transitive. That means T * 
const from C++ is not expressible in D. Any reference through a 
const becomes const. To use it, IMO your best bet is to make a 
wrapper function on the C++ side like this:

unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & 
im,class b2d::Context2D::InitParams const * const InitParams)
{
     return //the call to the original c++ function
}

Alternatively you can use dpp, or dstep or some similar tool to 
try and let the tool create bindings. As a last ditch, you can 
force the mangle to match by using pragma(mangle, ...) like this:

pragma(mangle, _ZactualMangleFromC++Compiler)
final uint _begin(ref Image image, const(InitParams) initParams);


More information about the Digitalmars-d-learn mailing list