GLib

Naming Conventions

GLib is a utility library which is heavily used in GTK+ and most of GNOME. GLib's functions are named starting with g_ (such as g_strdup), GLib's typedefs for common types are just prefixed with a g (such as gint32), and GLib's structures are capitalized and start with G (such as GHashTable).

Typedefs

GLib provides some portability typedefs, such as gint32, gint8, or just simplification typedefs such as guint (for unsigned int) and some typedefs which are present just to keep everything looking consistent, such as gint which just typedefs to int, or gpointer which is a typedef of void *.

Portability and Utility Functions

There are some functions that have different implementations across different systems or are not extremely safe, or don't exist at all on some systems, so GLib provides it's own implementations or wrappers that have a constant behavior and usually check their arguments. Examples of such functions are g_strdup, g_snprintf or g_malloc and g_free and more.

GLib also includes a lot of utility functions such as g_strconcat or g_strdup_printf and others, that are just plain useful.

Containers

Although probably the best part of GLib are the containers. Such as linked lists (GList) or re-sizable arrays (Array) or hash tables (GHashTable) and others. The easiest to use are GList's. The basic GList structure is just a single node of the linked list and you can put your data into the data pointer in the GList structure. To store a linked list you just store a pointer to the first node of the list. So code that would create a linked list of two elements which are strdup'ed strings, and later free that list and the strings would look like:

GList *list = NULL; /*the actual list pointer*/
GList *li; /*just a temporary pointer to a node used for iterating
	     over the list*/
...
/*here we add two strings to the list*/
list = g_list_append(list,g_strdup("String 1"));
list = g_list_append(list,g_strdup("String 2"));
...
/*here we loop though the list, freeing all the strings and then
  we free the list itself*/
for(li = list; li!= NULL; li = g_list_next(li)) {
	char *string = li->data;
	g_free(string);
}
g_list_free(list);

For more information look at the glib.h header file and at the documentation on the www.gtk.org web site.