Passing string from D to c++

deadalnix deadalnix at gmail.com
Tue Jul 30 22:39:54 PDT 2013


On Tuesday, 30 July 2013 at 19:52:44 UTC, Milvakili wrote:
> I'm linking D with C++ lib.a file.  When the C++ function has 
> compatible data types I can call them from D.  But when I 
> changed the parameter to string I got bunch of errors.
>
> Data Type Compatibility table does not include strings.  Is 
> there a way of passing strings?

When it come to C++, passing via C string is always an option, 
but kind of a waste as you'll allocate a temporary string and go 
through it twice.

My solution of choice it to create a function in C++ that take a 
const char* and a size_t length as parameter (and other C++ 
parameters of the function and forward to C++ .

Doing so, you only allocate the C++ string as C++ mandate and 
don't need to go through it. But you need a wrapper.


More information about the Digitalmars-d mailing list