libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
libcmutils

A C99 utility library for Linux, macOS and Windows, written so that one source tree builds unchanged on all three.

Objects are structs of function pointers

An object is a struct whose members are its methods, and every method takes the object as its first argument. The CMCall macro fills that argument in:

CMCall(str, AddString, "hello"); // str->AddString(str, "hello")
printf("%s\n", CMCall(str, GetCString));
CMCall(str, Destroy);
#define CMCall
Method caller for this library.
Definition libcmutils.h:475
#define CMUTIL_StringCreate()
Creates a string object.
Definition libcmutils.h:1752
Multifunctional string type.
Definition libcmutils.h:1423

Two rules come with it. Whether a CMCall may appear inside another one's argument list depends on the compiler - see CMUTIL_CALL_NESTED - and whether the receiver is evaluated once or twice likewise - see CMUTIL_CALL_SINGLE_EVAL. Both detect what the compiler supports and can be overridden before including this header.

Lifecycle

CMUTIL_Init(CMMemRecycle); // first library call in the process
...
CMUTIL_Clear(); // returns CMFalse if anything leaked
void CMUTIL_Init(CMMemOper memoper)
Initialize this library. This function must be called before calling any function in this library.
@ CMMemRecycle
Definition libcmutils.h:534

CMUTIL_Clear() reports whether every object allocated through the library was released, which makes it a leak check as well as a teardown.

Where to look

Topics, in the bar above, groups the API by subject - start there if you know roughly what you need. Data Structures lists the object types, and the search box finds anything by name.

Elsewhere:

  • Project page - the same API in prose, with the reasoning behind the conventions.
  • Repository - source, issues and releases.
  • Samples - one annotated, runnable program per subject.