version
GTK+ library as of writing in version 2.8.x is very dynamic,
and changes quite  often [about every 6 months a new release is made].
So with  this release schedule, API changes *can* occur; a support
for experimental features will change, or be dropped etc.

Now if you want widget_x to be present, which is in GTK+ API version 2.4.0
then you must write code like  this:

#if GTK_CHECK_VERSION(2,4,0)
    w=gtk_WidgetX_new();
#else
    w=gtk_label_new("Sorry dude, you dont have  this  2.4.0 GTK+ version,");
#endif 

so that your program is usable even though certain features arent enabled,
but will compile no matter. This is an advantage of using GTK_CHECK_VERSION()
and using it to try and make portable ABI, API compatible programs.


Example
/* code GPL'ed from Leafpad, by Tarot Osuji  */

GtkWidget *create_about_dialog(
		const gchar *name,
		const gchar *version,
		const gchar *copyright,
		const gchar *comments,
		const gchar **authors,
		const gchar **documenters,
		const gchar *translator_credits,
		GdkPixbuf *logo)
{
GtkWidget *about;
	
#if GTK_CHECK_VERSION(2, 6, 0)
	about = g_object_new(GTK_TYPE_ABOUT_DIALOG,
		"name",               name,
		"version",            version,
		"copyright",          copyright,
		"comments",           comments,
		"authors",            authors,
		"documenters",        documenters,
		"translator_credits", translator_credits,
		"logo",               logo,
		NULL);
#else
	about = my_gtk_about_new(
		name,
		version,
		copyright,
		comments,
		authors,
		documenters,
		translator_credits,
		logo);
#endif
	
	return about;
}

Here the program uses, a check for version 2.6 or later to use the
 gtk_about_dialog_new() or create a GTK_TYPE_ABOUT_DIALOG object,
and this  type doesnt come on older versions of GTK+ < 2.6.0 or earlier.
Thus GTK+ code compiles, but this feature replaced, or turned off.

Last Modified on Fri Jul 1 19:54:38 IST 2005
This is part of the GtkBook project Hosted Here
This code, documents and images are © Muthiah Annamalai
This document is under Creative Commons License given by LICENSE