glib 基本知识
基本类型
函数
#define G_GINT64_CONSTANT(val) (val##L)
#define G_GUINT64_CONSTANT(val) (val##UL)
#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)
类型和值
- 新类型,不是标准C的类型: gboolean, gsize, gsszie, goffset, gintptr, guintptr.
- 保证跨平台一致的整数类型:gint8, guint8, gint16, guint16, gint32, guint32, gint64, guint64.
- 比标准C对应的更好用的类型:gpointer, gconstpointer, guchar, guint, gushort, gulong.
- 与标准C的类型一致,但为了基本类型的完整性而定义:gchar, gint, gshort, glong, gfloat.
大部分类型都十分易懂,值得留意的是gpointer即是void 指针,gconstopointer是const void指针
标准宏
函数
-
#define G_IS_DIR_SEPARATOR()
是否路径分隔符 返回TRUE 或者FALSE -
#define MIN()
取较小者 MIN(1,2) -
#define MAX()
取较大者 -
#define ABS()
取绝对值 -
#define CLAMP()
CLMAP(x, low, high) x比low小取low , 比high大取high , 介于两者返回x -
#define G_STRUCT_MEMBER_P(struct_p, struct_offset)
((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
返回从Struct_p偏移struct_offset个bytes的gpointer指针 -
#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)
((member_type) G_STRUCT_MEMBER_P ((struct_p), (struct_offset))) -
#define G_STRUCT_OFFSET(struct_type, member)
((glong) offsetof (struct_type, member)) -
#define G_STRUCT_OFFSET(struct_type, member)
((glong) ((guint8) &((struct_type) 0)->member)
返回member的偏移值
类型和值
- #define G_OS_WIN32
- #define G_OS_UNIX
- #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 G_MEM_ALIGN
- #define G_CONST_RETURN
各个宏的意义显而易见
类型转换宏
函数
- #define GINT_TO_POINTER()
- #define GPOINTER_TO_INT()
- #define GUINT_TO_POINTER()
- #define GPOINTER_TO_UINT()
- #define GSIZE_TO_POINTER()
- #define GPOINTER_TO_SIZE()
各个宏的意义显而易见