Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Gtk+/Gnome Application Development
Prev Home Next

glib: Portability and Utility

glib is a C portability and utility library for UNIX-like systems and Windows. This chapter covers some of the most commonly-used library features in GTK+ and Gnome applications. glib is simple, and the concepts are familiar; so we'll move quickly. For more complete coverage of glib, see glib.h or the free glib reference manual that comes with the library. (By the way: don't be afraid of using the glib, GTK+, or Gnome header files; they are very clean and easy to read, and are handy as a quick reference. For that matter, don't be afraid to look at the source code, if you have very specific questions about the implementation.)

glib's various facilities are intended to have a consistent interface; the coding style is semi-object-oriented, and identifiers are prefixed with "g" to create a kind of namespace.

glib has a single header file, glib.h.

Basics

glib provides substitutes for many standard and commonly-used C language constructs. This section describes glib's fundamental type definitions, macros, memory allocation routines, and string utility functions.

Type Definitions

Rather than using C's standard types (int, long, etc.) glib defines its own. These serve a variety of purposes. For example, gint32 is guaranteed to be 32 bits wide, something no standard C type can ensure. guint is simply easier to type than unsigned. A few of the typedefs exist only for consistency; for example, gchar is always equivalent to the standard char.

The following primitive types are defined by glib:

  • gint8, guint8, gint16, guint16, gint32, guint32, gint64, guint64---these give you integers of a guaranteed size. Not all platforms provide 64-bit integers; if a platform has them, glib will define G_HAVE_GINT64. (If it isn't obvious, the guint types are unsigned, the gint types are signed.)

  • gboolean is useful to make your code more readable, since C has no bool type.

  • gchar, gshort, glong, gint, gfloat, gdouble are purely cosmetic.

  • gpointer may be more convenient to type than void *. gconstpointer gives you const void*. (const gpointer will not do what you typically mean it to; spend some time with a good book on C if you don't see why.)

Gtk+/Gnome Application Development
Prev Home Next

 
 
  Published under free license. Design by Interspire