manpagez: man pages & more
html files: glib
Home | html | info | man

Basic Types

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

Functions

GLIB_AVAILABLE_IN_ALL gint ()
GLIB_AVAILABLE_IN_ALL guint ()
#define G_GINT64_CONSTANT()
#define G_GUINT64_CONSTANT()
#define G_GOFFSET_CONSTANT()

Types and Values

typedef gboolean
typedef gpointer
typedef gconstpointer
typedef gchar
typedef guchar
#define G_MININT
#define G_MAXINT
#define G_MAXUINT
typedef gshort
#define G_MINSHORT
#define G_MAXSHORT
typedef gushort
#define G_MAXUSHORT
typedef glong
#define G_MINLONG
#define G_MAXLONG
typedef gulong
#define G_MAXULONG
typedef gint8
#define G_MININT8
#define G_MAXINT8
typedef guint8
#define G_MAXUINT8
typedef gint16
#define G_MININT16
#define G_MAXINT16
#define G_GINT16_MODIFIER
#define G_GINT16_FORMAT
typedef guint16
#define G_MAXUINT16
#define G_GUINT16_FORMAT
typedef gint32
#define G_MININT32
#define G_MAXINT32
#define G_GINT32_MODIFIER
#define G_GINT32_FORMAT
typedef guint32
#define G_MAXUINT32
#define G_GUINT32_FORMAT
typedef gint64
#define G_MININT64
#define G_MAXINT64
#define G_GINT64_MODIFIER
#define G_GINT64_FORMAT
typedef guint64
#define G_MAXUINT64
#define G_GUINT64_FORMAT
typedef gfloat
#define G_MINFLOAT
#define G_MAXFLOAT
typedef gdouble
#define G_MINDOUBLE
#define G_MAXDOUBLE
typedef gsize
#define G_MAXSIZE
#define G_GSIZE_MODIFIER
#define G_GSIZE_FORMAT
typedef gssize
#define G_MINSSIZE
#define G_MAXSSIZE
#define G_GSSIZE_MODIFIER
#define G_GSSIZE_FORMAT
typedef goffset
#define G_MINOFFSET
#define G_MAXOFFSET
#define G_GOFFSET_MODIFIER
#define G_GOFFSET_FORMAT
typedef gintptr
#define G_GINTPTR_MODIFIER
#define G_GINTPTR_FORMAT
typedef guintptr
#define G_GUINTPTR_FORMAT

Includes

#include <glib.h>

Description

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

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

gint ()

GLIB_AVAILABLE_IN_ALL
gint ();

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


guint ()

GLIB_AVAILABLE_IN_ALL
guint ();

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


G_GINT64_CONSTANT()

#define G_GINT64_CONSTANT(val) (val##L)

This macro is used to insert 64-bit integer literals into the source code.

Parameters

val

a literal integer value, e.g. 0x1d636b02300a7aa7

 

G_GUINT64_CONSTANT()

#define G_GUINT64_CONSTANT(val) (val##UL)

This macro is used to insert 64-bit unsigned integer literals into the source code.

Parameters

val

a literal integer value, e.g. 0x1d636b02300a7aa7U

 

Since: 2.10


G_GOFFSET_CONSTANT()

#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)

This macro is used to insert goffset 64-bit integer literals into the source code.

See also G_GINT64_CONSTANT.

Parameters

val

a literal integer value, e.g. 0x1d636b02300a7aa7

 

Since: 2.20

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.


G_MININT

#define G_MININT INT_MIN

The minimum value which can be held in a gint.


G_MAXINT

#define G_MAXINT INT_MAX

The maximum value which can be held in a gint.


G_MAXUINT

#define G_MAXUINT UINT_MAX

The maximum value which can be held in a guint.


gshort

typedef short  gshort;

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


G_MINSHORT

#define G_MINSHORT SHRT_MIN

The minimum value which can be held in a gshort.


G_MAXSHORT

#define G_MAXSHORT SHRT_MAX

The maximum value which can be held in a gshort.


gushort

typedef unsigned short  gushort;

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


G_MAXUSHORT

#define G_MAXUSHORT USHRT_MAX

The maximum value which can be held in a gushort.


glong

typedef long   glong;

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


G_MINLONG

#define G_MINLONG LONG_MIN

The minimum value which can be held in a glong.


G_MAXLONG

#define G_MAXLONG LONG_MAX

The maximum value which can be held in a glong.


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_MAXULONG

#define G_MAXULONG ULONG_MAX

The maximum value which can be held in a gulong.


gint8

typedef signed char gint8;

A signed integer guaranteed to be 8 bits on all platforms. Values of this type can range from G_MININT8 (= -128) to G_MAXINT8 (= 127).


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


guint8

typedef unsigned char guint8;

An unsigned integer guaranteed to be 8 bits on all platforms. Values of this type can range from 0 to G_MAXUINT8 (= 255).


G_MAXUINT8

#define G_MAXUINT8 ((guint8) 0xff)

The maximum value which can be held in a guint8.

Since: 2.4


gint16

typedef signed short gint16;

A signed integer guaranteed to be 16 bits on all platforms. Values of this type can range from G_MININT16 (= -32,768) to G_MAXINT16 (= 32,767).

To print or scan values of this type, use G_GINT16_MODIFIER and/or G_GINT16_FORMAT.


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_GINT16_MODIFIER

#define G_GINT16_MODIFIER "h"

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gint16 or guint16. It is a string literal, but doesn't include the percent-sign, such that you can add precision and length modifiers between percent-sign and conversion specifier and append a conversion specifier.

The following example prints "0x7b";

1
2
gint16 value = 123;
g_print ("%#" G_GINT16_MODIFIER "x", value);

Since: 2.4


G_GINT16_FORMAT

#define G_GINT16_FORMAT "hi"

This is the platform dependent conversion specifier for scanning and printing values of type gint16. It is a string literal, but doesn't include the percent-sign, such that you can add precision and length modifiers between percent-sign and conversion specifier.

1
2
3
4
5
gint16 in;
gint32 out;
sscanf ("42", "%" G_GINT16_FORMAT, &in)
out = in * 1000;
g_print ("%" G_GINT32_FORMAT, out);


guint16

typedef unsigned short guint16;

An unsigned integer guaranteed to be 16 bits on all platforms. Values of this type can range from 0 to G_MAXUINT16 (= 65,535).

To print or scan values of this type, use G_GINT16_MODIFIER and/or G_GUINT16_FORMAT.


G_MAXUINT16

#define G_MAXUINT16 ((guint16) 0xffff)

The maximum value which can be held in a guint16.

Since: 2.4


G_GUINT16_FORMAT

#define G_GUINT16_FORMAT "hu"

This is the platform dependent conversion specifier for scanning and printing values of type guint16. See also G_GINT16_FORMAT


gint32

typedef signed int gint32;

A signed integer guaranteed to be 32 bits on all platforms. Values of this type can range from G_MININT32 (= -2,147,483,648) to G_MAXINT32 (= 2,147,483,647).

To print or scan values of this type, use G_GINT32_MODIFIER and/or G_GINT32_FORMAT.


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_GINT32_MODIFIER

#define G_GINT32_MODIFIER ""

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gint32 or guint32. It is a string literal. See also G_GINT16_MODIFIER.

Since: 2.4


G_GINT32_FORMAT

#define G_GINT32_FORMAT "i"

This is the platform dependent conversion specifier for scanning and printing values of type gint32. See also G_GINT16_FORMAT.


guint32

typedef unsigned int guint32;

An unsigned integer guaranteed to be 32 bits on all platforms. Values of this type can range from 0 to G_MAXUINT32 (= 4,294,967,295).

To print or scan values of this type, use G_GINT32_MODIFIER and/or G_GUINT32_FORMAT.


G_MAXUINT32

#define G_MAXUINT32 ((guint32) 0xffffffff)

The maximum value which can be held in a guint32.

Since: 2.4


G_GUINT32_FORMAT

#define G_GUINT32_FORMAT "u"

This is the platform dependent conversion specifier for scanning and printing values of type guint32. See also G_GINT16_FORMAT.


gint64

typedef signed long gint64;

A signed integer guaranteed to be 64 bits on all platforms. Values of this type can range from G_MININT64 (= -9,223,372,036,854,775,808) to G_MAXINT64 (= 9,223,372,036,854,775,807).

To print or scan values of this type, use G_GINT64_MODIFIER and/or G_GINT64_FORMAT.


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_GINT64_MODIFIER

#define G_GINT64_MODIFIER "l"

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gint64 or guint64. It is a string literal.

Some platforms do not support printing 64-bit integers, even though the types are supported. On such platforms G_GINT64_MODIFIER is not defined.

Since: 2.4


G_GINT64_FORMAT

#define G_GINT64_FORMAT "li"

This is the platform dependent conversion specifier for scanning and printing values of type gint64. See also G_GINT16_FORMAT.

Some platforms do not support scanning and printing 64-bit integers, even though the types are supported. On such platforms G_GINT64_FORMAT is not defined. Note that scanf() may not support 64-bit integers, even if G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not recommended for parsing anyway; consider using g_ascii_strtoull() instead.


guint64

typedef unsigned long guint64;

An unsigned integer guaranteed to be 64-bits on all platforms. Values of this type can range from 0 to G_MAXUINT64 (= 18,446,744,073,709,551,615).

To print or scan values of this type, use G_GINT64_MODIFIER and/or G_GUINT64_FORMAT.


G_MAXUINT64

#define G_MAXUINT64 G_GUINT64_CONSTANT(0xffffffffffffffff)

The maximum value which can be held in a guint64.


G_GUINT64_FORMAT

#define G_GUINT64_FORMAT "lu"

This is the platform dependent conversion specifier for scanning and printing values of type guint64. See also G_GINT16_FORMAT.

Some platforms do not support scanning and printing 64-bit integers, even though the types are supported. On such platforms G_GUINT64_FORMAT is not defined. Note that scanf() may not support 64-bit integers, even if G_GINT64_FORMAT is defined. Due to its weak error handling, scanf() is not recommended for parsing anyway; consider using g_ascii_strtoull() instead.


gfloat

typedef float   gfloat;

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


G_MINFLOAT

#define G_MINFLOAT FLT_MIN

The minimum positive value which can be held in a gfloat.

If you are interested in the smallest value which can be held in a gfloat, use -G_MAXFLOAT.


G_MAXFLOAT

#define G_MAXFLOAT FLT_MAX

The maximum value which can be held in a gfloat.


gdouble

typedef double  gdouble;

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


G_MINDOUBLE

#define G_MINDOUBLE DBL_MIN

The minimum positive value which can be held in a gdouble.

If you are interested in the smallest value which can be held in a gdouble, use -G_MAXDOUBLE.


G_MAXDOUBLE

#define G_MAXDOUBLE DBL_MAX

The maximum value which can be held in a gdouble.


gsize

typedef unsigned long gsize;

An unsigned integer type of the result of the sizeof operator, corresponding to the size_t type defined in C99. This type is wide enough to hold the numeric value of a pointer, so it is usually 32 bit wide on a 32-bit platform and 64 bit wide on a 64-bit platform. Values of this type can range from 0 to G_MAXSIZE.

To print or scan values of this type, use G_GSIZE_MODIFIER and/or G_GSIZE_FORMAT.


G_MAXSIZE

#define G_MAXSIZE G_MAXULONG

The maximum value which can be held in a gsize.

Since: 2.4


G_GSIZE_MODIFIER

#define G_GSIZE_MODIFIER "l"

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gsize. It is a string literal.

Since: 2.6


G_GSIZE_FORMAT

#define G_GSIZE_FORMAT "lu"

This is the platform dependent conversion specifier for scanning and printing values of type gsize. See also G_GINT16_FORMAT.

Since: 2.6


gssize

typedef signed long gssize;

A signed variant of gsize, corresponding to the ssize_t defined on most platforms. Values of this type can range from G_MINSSIZE to G_MAXSSIZE.

To print or scan values of this type, use G_GSSIZE_MODIFIER and/or G_GSSIZE_FORMAT.


G_MINSSIZE

#define G_MINSSIZE G_MINLONG

The minimum value which can be held in a gssize.

Since: 2.14


G_MAXSSIZE

#define G_MAXSSIZE G_MAXLONG

The maximum value which can be held in a gssize.

Since: 2.14


G_GSSIZE_MODIFIER

#define G_GSSIZE_MODIFIER "l"

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gssize. It is a string literal.

Since: 2.6


G_GSSIZE_FORMAT

#define G_GSSIZE_FORMAT "li"

This is the platform dependent conversion specifier for scanning and printing values of type gssize. See also G_GINT16_FORMAT.

Since: 2.6


goffset

typedef gint64 goffset;

A signed integer type that is used for file offsets, corresponding to the POSIX type off_t as if compiling with _FILE_OFFSET_BITS set to 64. goffset is always 64 bits wide, even on 32-bit architectures. Values of this type can range from G_MINOFFSET to G_MAXOFFSET.

To print or scan values of this type, use G_GOFFSET_MODIFIER and/or G_GOFFSET_FORMAT.

Since: 2.14


G_MINOFFSET

#define G_MINOFFSET G_MININT64

The minimum value which can be held in a goffset.


G_MAXOFFSET

#define G_MAXOFFSET G_MAXINT64

The maximum value which can be held in a goffset.


G_GOFFSET_MODIFIER

#define G_GOFFSET_MODIFIER      G_GINT64_MODIFIER

The platform dependent length modifier for conversion specifiers for scanning and printing values of type goffset. It is a string literal. See also G_GINT64_MODIFIER.

Since: 2.20


G_GOFFSET_FORMAT

#define G_GOFFSET_FORMAT        G_GINT64_FORMAT

This is the platform dependent conversion specifier for scanning and printing values of type goffset. See also G_GINT64_FORMAT.

Since: 2.20


gintptr

typedef signed long gintptr;

Corresponds to the C99 type intptr_t, a signed integer type that can hold any pointer.

To print or scan values of this type, use G_GINTPTR_MODIFIER and/or G_GINTPTR_FORMAT.

Since: 2.18


G_GINTPTR_MODIFIER

#define G_GINTPTR_MODIFIER      "l"

The platform dependent length modifier for conversion specifiers for scanning and printing values of type gintptr or guintptr. It is a string literal.

Since: 2.22


G_GINTPTR_FORMAT

#define G_GINTPTR_FORMAT        "li"

This is the platform dependent conversion specifier for scanning and printing values of type gintptr.

Since: 2.22


guintptr

typedef unsigned long guintptr;

Corresponds to the C99 type uintptr_t, an unsigned integer type that can hold any pointer.

To print or scan values of this type, use G_GINTPTR_MODIFIER and/or G_GUINTPTR_FORMAT.

Since: 2.18


G_GUINTPTR_FORMAT

#define G_GUINTPTR_FORMAT       "lu"

This is the platform dependent conversion specifier for scanning and printing values of type guintptr.

Since: 2.22

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.