Reputation: 155
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
Upvotes: 2
Views: 54
Reputation: 4043
Chapel deprecated the c_string
type in last week's 1.32 release in favor of c_ptrConst(c_char)
, which is Chapel's transliteration of const 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_string
that needs updating, please refer to https://chapel-lang.org/docs/1.32/language/evolution.html#c-string-deprecation for additional information.
Upvotes: 2