cthreadcomm · Section 3
ceventloop_declare_scoped
NAME
ceventloop_declare_scoped - declare a ceventloop with automatic destruction on scope exit
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cthreadcomm.h> ceventloop_declare_scoped(name);
DESCRIPTION
Declares a ceventloop variable set to CEVENTLOOP_NULL and tags it with a cleanup attribute, so the loop is destroyed automatically, exactly as ceventloop_destroy() would do it, when the variable leaves its scope. You must assign the variable with ceventloop_construct() or a ceventloop_create*() call before you use it. When the declaration and the initialisation can happen in one place, which is the common case, use ceventloop_construct_scoped() instead.
PARAMETERS
name Variable name to declare.
NOTES
The macro uses __attribute__((cleanup)), so it needs GCC or Clang. Leaving the variable at CEVENTLOOP_NULL for the whole scope is safe, because the cleanup does nothing for that value.
EXAMPLES
{
ceventloop_declare_scoped(loop);
char *err = NULL;
loop = ceventloop_create(32, 1, 1, &err);
if (!loop) { fprintf(stderr, "%s\n", err); return; }
/* ... */
} /* the library destroys loop automatically here */
SEE ALSO
ceventloop_declare(3), ceventloop_construct_scoped(3), ceventloop_create(3), ceventloop_destroy(3)