Standard Macros

Name

Standard Macros -- commonly-used macros.

Synopsis


#include <glib.h>


#define     GLIB_MAJOR_VERSION
#define     GLIB_MINOR_VERSION
#define     GLIB_MICRO_VERSION

#define     GLIB_CHECK_VERSION              (major,minor,micro)

#define     G_DIR_SEPARATOR
#define     G_DIR_SEPARATOR_S
#define     G_SEARCHPATH_SEPARATOR
#define     G_SEARCHPATH_SEPARATOR_S

#define     TRUE
#define     FALSE

#define     NULL

#define     MIN                             (a, b)
#define     MAX                             (a, b)

#define     ABS                             (a)
#define     CLAMP                           (x, low, high)

#define     G_STRUCT_MEMBER                 (member_type, struct_p, struct_offset)
#define     G_STRUCT_MEMBER_P               (struct_p, struct_offset)
#define     G_STRUCT_OFFSET                 (struct_type, member)

Description

These macros provide a few commonly-used features.

Details

GLIB_MAJOR_VERSION

#define GLIB_MAJOR_VERSION 1

The major version number of the GLib library.


GLIB_MINOR_VERSION

#define GLIB_MINOR_VERSION 2

The minor version number of the GLib library.


GLIB_MICRO_VERSION

#define GLIB_MICRO_VERSION 3

The micro version number of the GLib library.


GLIB_CHECK_VERSION()

#define     GLIB_CHECK_VERSION(major,minor,micro)

Checks the version of the GLib library. It returns TRUE if the GLib library is the same or newer than the given version.

Example 1. Checking the version of the GLib library.

  if (!GLIB_CHECK_VERSION (1, 2, 0))
    g_error ("GLib version 1.2.0 or above is needed");

major :the major version number.
minor :the minor version number.
micro :the micro version number.


G_DIR_SEPARATOR

#define     G_DIR_SEPARATOR

The directory separator character. This is '/' on Unix machines and '\' under Windows.


G_DIR_SEPARATOR_S

#define     G_DIR_SEPARATOR_S

The directory separator as a string. This is "/" on Unix machines and "\" under Windows.


G_SEARCHPATH_SEPARATOR

#define     G_SEARCHPATH_SEPARATOR

The search path separator character. This is ':' on Unix machines and ';' under Windows.


G_SEARCHPATH_SEPARATOR_S

#define     G_SEARCHPATH_SEPARATOR_S

The search path separator as a string. This is ":" on Unix machines and ";" under Windows.


TRUE

#define	TRUE	(!FALSE)

Defines the TRUE value for the gboolean type.


FALSE

#define	FALSE	(0)

Defines the FALSE value for the gboolean type.


NULL

#define	NULL	((void*) 0)

Defines the standard NULL pointer.


MIN()

#define MIN(a, b)  (((a) < (b)) ? (a) : (b))

Calculates the minimum of a and b.

a :a numeric value.
b :a numeric value.
Returns :the minimum of a and b.


MAX()

#define MAX(a, b)  (((a) > (b)) ? (a) : (b))

Calculates the maximum of a and b.

a :a numeric value.
b :a numeric value.
Returns :the maximum of a and b.


ABS()

#define ABS(a)	   (((a) < 0) ? -(a) : (a))

Calculates the absolute value of a. The absolute value is simply the number with any negative sign taken away.

For example,

a :a numeric value.
Returns :the absolute value of a.


CLAMP()

#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))

Ensures that x is between the limits set by low and high.

For example,

x :the value to clamp.
low :the minimum value allowed.
high :the maximum value allowed.
Returns :the value of x clamped to the range between low and high.


G_STRUCT_MEMBER()

#define     G_STRUCT_MEMBER(member_type, struct_p, struct_offset)

Returns a member of a structure at a given offset, using the given type.

member_type :the type of the struct field.
struct_p :a pointer to a struct.
struct_offset :the offset of the field from the start of the struct, in bytes.
Returns :the struct member.


G_STRUCT_MEMBER_P()

#define     G_STRUCT_MEMBER_P(struct_p, struct_offset)

Returns an untyped pointer to a given offset of a struct.

struct_p :a pointer to a struct.
struct_offset :the offset from the start of the struct, in bytes.
Returns :an untyped pointer to struct_p plus struct_offset bytes.


G_STRUCT_OFFSET()

#define     G_STRUCT_OFFSET(struct_type, member)

Returns the offset, in bytes, of a member of a struct.

struct_type :a structure type, e.g. GtkWidget.
member :a field in the structure, e.g. window.
Returns :the offset of member from the start of struct_type.