Zeuthen: Writing a C library, part 1
Zeuthen: Writing a C library, part 1
David Zeuthen has posted a
set of guidelines for low-level library implementers. "Unless
it's self-evident, all functions should have documentation explaining how
parameters are managed. It is often a good idea to try to force some kind
of consistency on the API. For example, in the GLib stack the general rule
is that the caller owns parameters passed to a function (so the function
need to take a reference or make a copy if the parameter is used after the
function returns) and that the callee owns the returned parameters (so the
caller needs to make a copy or increase the reference count) unless the
function can be called from multiple threads (in which case the caller
needs to free the returned object).
"