Linking a C program with D library

Joe jma at freedomcircle.com
Wed Aug 15 02:40:22 UTC 2018


On Wednesday, 15 August 2018 at 01:56:34 UTC, Mike Parker wrote:
> The correct thing to do is to keep the original C function 
> signatures in the converted code, i.e. don't change char* to 
> string[]. And don't use anything from Phobos internally that 
> requires linking. In other words, treat your converted code as 
> C code in a D module as much as possible. Only when the 
> conversion is complete and everything is in D do you start 
> pulling in the D features.

I understand that, Mike. However if I'm not mistaken given 
something in C like

char* strs[] = { "This", "is a", "test"};

AFAIK, even with -betterC and an extern (C), the literals will 
still be understood by D as type "string", and there is no other 
way around it, right?

I could put the array and the function in its own C file for the 
time being, but instead chose to replace the toStringz by a small 
hack: use memcpy to copy the string to a stack fixed, big enough 
array and a NUL terminator.


More information about the Digitalmars-d-learn mailing list