Search code examples
cstringchard

Call a D function from C with string argument


OK, so basically, this is what I'm trying to do...

I have a D function like :

extern (C) {
  void someFunc(string s) {
    writeln("Got : " ~ s);
  }
}

I want to call this from C code with a char* argument.

How is that possible?


Solution

  • OK, just found the answer (there was no issue with how it was called, but how I converted the char * to a D-compatible string) :

    extern (C) {
      void myfunc(char* s) {
        writeln(to!string(s));
      }
    }