5

Suppose I have a Chapel string

var s : string;

How would I send it to a function that expects a char*(since c_string assumes const char *)?

1 Answers1

4

Here is an example that does this

extern {
  #include <stdio.h>
  static void f(char* argument) {
    printf("%s\n", argument);
  }
}

var s: string = "hello";
f(s.c_str():c_void_ptr:c_ptr(c_char));

Note the cast to c_void_ptr which is necessary before Chapel 1.19.

mppf
  • 1,820
  • 9
  • 9