如何将 Chapel 字符串传递给需要(非常量)char* 的 C 函数?

How can I pass a Chapel string to a C function that requires (non-const) char*?

假设我有一个 Chapel 字符串

var s : string;

我如何将它发送到需要 char* 的函数(因为 c_string 假设 const char *)?

这是一个执行此操作的示例

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));

注意在 Chapel 1.19 之前必须对 c_void_ptr 进行强制转换。