I'm new to the language, so perhaps I'm making a mistake, but this doesn't seem to work per the documentation. The documentation states:
proc string.c_str():c_ptrConst(c_char) Get a c_ptrConst(c_char) from a string. The returned c_ptrConst shares the buffer with the string.
But the following code produces a compiler error saying:
c_str.chpl:6: error: cannot initialize 'str_ptr' of type 'c_ptrConst(int(8))' from a 'c_string'
use CTypes;
var a_str:string = "elephant";
var str_ptr:c_ptrConst(c_char) = a_str.c_str();
That error seems to indicate that a c_string is returned, but I also see in the documentation the c_string is being deprecated.
Thanks,
Gene
Chapel deprecated the
c_stringtype in last week's 1.32 release in favor ofc_ptrConst(c_char), which is Chapel's transliteration ofconst char*in C.It sounds like you got bitten by using an older version of Chapel in combination with the latest documentation. Sorry for that confusion. For reference, the documentation for
.c_str()is at the following links for 1.31 vs. 1.32:For anyone interested in more context for the change, or who has old code using
c_stringthat needs updating, please refer to https://chapel-lang.org/docs/1.32/language/evolution.html#c-string-deprecation for additional information.