"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

Conversions

    Arrays

  • Array types can be Cast to managed C strings. Supported array types include "ListVector", "NumericArray" and "PackedArray".
  • "String"

  • Cast can be used to convert "String" objects to managed C strings.
  • "RawPointer" and "OpaqueRawPointer"

  • Cast can be used to bitcast C strings to and from raw pointers.

Examples

open allclose all

Basic Examples  (1)

Compile a function that creates a C string and passes it to the C standard library function strlen to get its length:

Evaluate the compiled function on a string:

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:

The function leaks memory:

Use DeleteObject to manually free the C strings:

The resulting function does not leak memory: