|
Functions
|
|
Function names begin with the name of structure they operate on followed by an underscore and the method name. Each structure has a new and free function.
Example:
List *List_new(void);
void List_free(List *self);
Example implementation of new and free functions:
List *List_new(void)
{
List *self = (List *)calloc(1, sizeof(List));
self->items = malloc(LIST_DEFAULT_SIZE);
return self;
}
void List_free(List *self)
{
free(self->items);
free(self);
}
Aside from new methods, all methods have the structure(the "object") as the first object with the variable named "self". Method names are in keyword format. That is, for each argument, the method name has a description followed by an underscore. The casing of the descriptions follow that of structure member names.
Examples:
int List_count(List *self); /* no argument */
void List_add_(List *self, void *item); /* one argument */
void Dictionary_key_value_(Dictionary *self, char *key, char *value);
|