"CString" (Compiled Type)
"CString"
represents a string compatible with C.
Details
- "CString" is a macro for "CArray"::["CChar"].
- "CString" is equivalent to char* or unsigned char* in C.
Constructors
- Unless wrapped with "Managed", C strings constructed with CreateTypeInstance are not automatically memory managed, and must be manually freed with DeleteObject. »
- CreateTypeInstance["CString",str] constructs a C string from a "String" str.
- CreateTypeInstance["CString",len] constructs a C string with length len.
- CreateTypeInstance["CString",cstr,len] constructs a copy of cstr with length len. If cstr is shorter than len, this can cause a crash.
- CreateTypeInstance["CString",cstr] constructs a copy of a null-terminated string cstr. If cstr is not null terminated, this can cause a crash.
Conversions
- Array types can be Cast to managed C strings. Supported array types include "ListVector", "NumericArray" and "PackedArray".
- Cast can be used to convert "String" objects to managed C strings.
- Cast can be used to bitcast C strings to and from raw pointers.
Arrays
"String"
"RawPointer" and "OpaqueRawPointer"
Examples
open allclose allBasic Examples (1)
Possible Issues (1)
C strings created outside of a "Managed" object are not automatically memory managed, and must be freed manually. Compile a function that creates unmanaged C strings:
Use DeleteObject to manually free the C strings: