C Collections

cstring · Section 3

cstring_destroy

cstring_destroy - destroy a string and set its pointer to NULL

C Collections (libccollections, -lccollections)

#include <ccollections/cstring.h>
 
cstring_destroy(s);

This macro destroys the cstring. It frees the internal buffer and the
container itself and then sets the pointer variable s to NULL, which
makes a second call safe.

s   cstr lvalue to destroy, such as a variable or an element of an
    array; the macro evaluates it exactly once and sets it to NULL

A call with a NULL pointer is safe and does nothing.
The internal buffer and the container are freed with the allocator that
created the string, which is the custom ccol_memmgmt_procs given to
cstring_create_full(), or free() when none was given.

cstr s = cstring_create("hello", NULL);
cstring_destroy(s);   /* s is now NULL */

cstr_destroy(3)