Basic Types

Basic Types — standard GLib types, defined for ease-of-use and portability

Types and Values

typedef gboolean
typedef gpointer
typedef gconstpointer
typedef gchar
typedef guchar
typedef gint
typedef guint
typedef gshort
typedef gushort
typedef glong
typedef gulong
#define G_MININT8
#define G_MAXINT8
#define G_MAXUINT8
#define G_MININT16
#define G_MAXINT16
#define G_MAXUINT16
#define G_MININT32
#define G_MAXINT32
#define G_MAXUINT32
#define G_MININT64
#define G_MAXINT64
#define G_MAXUINT64
typedef gfloat
typedef gdouble

Object Hierarchy


Includes

#include <glib.h>

Description

GLib defines a number of commonly used types, which can be divided into 4 groups:

  • New types which are not part of standard C (but are defined in various C standard library header files) - gboolean, gsize, gssize, goffset, gintptr, guintptr.

  • Integer types which are guaranteed to be the same size across all platforms - gint8, guint8, gint16, guint16, gint32, guint32, gint64, guint64.

  • Types which are easier to use than their standard C counterparts - gpointer, gconstpointer, guchar, guint, gushort, gulong.

  • Types which correspond exactly to standard C types, but are included for completeness - gchar, gint, gshort, glong, gfloat, gdouble.

GLib also defines macros for the limits of some of the standard integer and floating point types, as well as macros for suitable printf() formats for these types.

Functions

Types and Values

gboolean

typedef gint   gboolean;

A standard boolean type. Variables of this type should only contain the value TRUE or FALSE.


gpointer

typedef void* gpointer;

An untyped pointer. gpointer looks better and is easier to use than void*.


gconstpointer

typedef const void *gconstpointer;

An untyped pointer to constant data. The data pointed to should not be changed.

This is typically used in function prototypes to indicate that the data pointed to will not be altered by the function.


gchar

typedef char   gchar;

Corresponds to the standard C char type.


guchar

typedef unsigned char   guchar;

Corresponds to the standard C unsigned char type.


gint

typedef int    gint;

Corresponds to the standard C int type. Values of this type can range from G_MININT to G_MAXINT.


guint

typedef unsigned int    guint;

Corresponds to the standard C unsigned int type. Values of this type can range from 0 to G_MAXUINT.


gshort

typedef short  gshort;

Corresponds to the standard C short type. Values of this type can range from G_MINSHORT to G_MAXSHORT.


gushort

typedef unsigned short  gushort;

Corresponds to the standard C unsigned short type. Values of this type can range from 0 to G_MAXUSHORT.


glong

typedef long   glong;

Corresponds to the standard C long type. Values of this type can range from G_MINLONG to G_MAXLONG.


gulong

typedef unsigned long   gulong;

Corresponds to the standard C unsigned long type. Values of this type can range from 0 to G_MAXULONG.


G_MININT8

#define G_MININT8 ((gint8)  0x80)

The minimum value which can be held in a gint8.

Since 2.4


G_MAXINT8

#define G_MAXINT8 ((gint8)  0x7f)

The maximum value which can be held in a gint8.

Since 2.4


G_MAXUINT8

#define G_MAXUINT8 ((guint8) 0xff)

The maximum value which can be held in a guint8.

Since 2.4


G_MININT16

#define G_MININT16 ((gint16)  0x8000)

The minimum value which can be held in a gint16.

Since 2.4


G_MAXINT16

#define G_MAXINT16 ((gint16)  0x7fff)

The maximum value which can be held in a gint16.

Since 2.4


G_MAXUINT16

#define G_MAXUINT16 ((guint16) 0xffff)

The maximum value which can be held in a guint16.

Since 2.4


G_MININT32

#define G_MININT32 ((gint32)  0x80000000)

The minimum value which can be held in a gint32.

Since 2.4


G_MAXINT32

#define G_MAXINT32 ((gint32)  0x7fffffff)

The maximum value which can be held in a gint32.

Since 2.4


G_MAXUINT32

#define G_MAXUINT32 ((guint32) 0xffffffff)

The maximum value which can be held in a guint32.

Since 2.4


G_MININT64

#define G_MININT64 ((gint64) G_GINT64_CONSTANT(0x8000000000000000))

The minimum value which can be held in a gint64.


G_MAXINT64

#define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff)

The maximum value which can be held in a gint64.


G_MAXUINT64

#define G_MAXUINT64 G_GINT64_CONSTANT(0xffffffffffffffffU)

The maximum value which can be held in a guint64.


gfloat

typedef float   gfloat;

Corresponds to the standard C float type. Values of this type can range from -G_MAXFLOAT to G_MAXFLOAT.


gdouble

typedef double  gdouble;

Corresponds to the standard C double type. Values of this type can range from -G_MAXDOUBLE to G_MAXDOUBLE.