"CString" (Compiled Type)
"CString"
represents a string compatible with 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)
Scope (1)
Compile a function that parses a C string to a number using the atof library function from the C standard:
Evaluate the compiled function:
Convert a "CInt" to a string and store it in a managed C string of size 512:
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: