# pcb-rnd - plugin development - plugin cookie

Many of the pcb-rnd infrastructure API requires a cookie for registering new objects. This cookie is typically a const char *, which is used only in pointer comparison. It is also useful for debugging: when objects are not unregistered properly, the code can print the value (string) of the cookie in the error message, which can be a hint on the source of the registration.

The cookie should be a static const char string, normally on top of the main c file of the plugin:

    static const char *pluginname_cookie = "pluginname + a 2..3 word description";

## multiple cookies

The plugin may use multiple cookies, e.g. different cookie for registering different set of objects, if that potentially helps debugging. This is especially useful if the plugin is consists of largely independent subsystems - each subsystem can have its own cookie.

## multiple source files vs. cookies

If the plugin contains multiple compilation units (object files), these files may need to use the same cookie. In that case pluginname_cookie should not be static and shall be exposed in a plugin header file using extern.

Since cookies are used by pointer, it is important not to copy the string into multiple objects - those copies will not match. This can happen accidentally on some systems if the header is missing extern.