cyaml · Section 3
cyaml_declare_scoped
NAME
cyaml_declare_scoped - declare a cyaml variable with automatic RAII destruction
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cyaml.h> cyaml_declare_scoped(var_name);
DESCRIPTION
Declares a cyaml handle named var_name, sets it to NULL and attaches a cleanup attribute to it. When var_name goes out of scope, the cleanup frees the whole tree that the variable holds, exactly as cyaml_destroy() does, and leaves the variable NULL. Cleanups run at the end of the enclosing block in reverse declaration order, whether the block exits normally or through break, continue, return or goto. The macro relies on a GCC and Clang extension that MSVC doesn't have.
PARAMETERS
var_name Name of the variable to declare.
EXAMPLES
{
cyaml_declare_scoped(doc);
doc = cyaml_parse("x: 1\n", NULL);
if (!doc) return;
/* ... use doc ... */
} /* doc is freed automatically here */