标准宏

标准宏 — 常见宏。

Synopsis

#include <glib.h>

#define             G_OS_WIN32
#define             G_OS_BEOS
#define             G_OS_UNIX

#define             G_DIR_SEPARATOR
#define             G_DIR_SEPARATOR_S
#define             G_IS_DIR_SEPARATOR                  (c)
#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)

#define             G_MEM_ALIGN

#define             G_CONST_RETURN

Description

这些宏提供一些常用的功能。

Details

G_OS_WIN32

#define G_OS_WIN32

这些宏只在Windows上定义。所以你要使用针对于Windows的特定代码 "#ifdef G_OS_WIN32"。


G_OS_BEOS

#define G_OS_BEOS

这些宏只在BeOS上定义。所以你要使用针对于BeOS的特定代码 "#ifdef G_OS_BEOS"。


G_OS_UNIX

#define G_OS_UNIX

这些宏只在UNIX上定义。所以你要使用针对于UNIX的特定代码 "#ifdef G_OS_UNIX"。


G_DIR_SEPARATOR

#define G_DIR_SEPARATOR '\\'

目录分隔符。’/’是UNIX机器上的,’\’是Windows环境下的。


G_DIR_SEPARATOR_S

#define G_DIR_SEPARATOR_S "\\"

目录分隔字符串。”/”是UNIX机器上的,”\”是Windows环境下的。


G_IS_DIR_SEPARATOR()

#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')

检查一个字符是否是目录分隔符。'/'在UNIX机器上,以及'\' 和 '/' 在Windows下,会返回一个TRUE

c :

一个字符

Since 2.6


G_SEARCHPATH_SEPARATOR

#define G_SEARCHPATH_SEPARATOR ';'

搜索路径分隔符。':'是UNIX机器上的,';'则是Windows下的。


G_SEARCHPATH_SEPARATOR_S

#define G_SEARCHPATH_SEPARATOR_S ";"

搜索路径分隔字符串。':'是UNIX机器上的,';'则是Windows下的。


TRUE

#define TRUE (!FALSE)

定义gboolean类型的TRUE


FALSE

#define FALSE (0)

定义gboolean类型的% FALSE。


NULL

#    define NULL        (0L)

定义标准的NULL 指针。


MIN()

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

计算ab哪个小。

a :

一个数值变量。

b :

一个数值变量。

Returns :

ab之中更小的

MAX()

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

计算ab哪个大。

a :

一个数值变量。

b :

一个数值变量。

Returns :

ab之中更大的

ABS()

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

计算a的绝对值。绝对值仅仅是对任何数去掉负号。

例如:

  • ABS(-10) 绝对值为10.

  • ABS(10) 还是 10.

a :

一个数值变量。

Returns :

a的绝对值。

CLAMP()

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

确保xlowhigh之间。如果low大于high,结果是未知的。

例如:

  • CLAMP(5, 10, 15) 结果是 10。

  • CLAMP(15, 5, 10) 结果是10.

  • CLAMP(20, 15, 25) 结果是20.

x :

the value to clamp.【不清楚这里如何理解】

low :

允许的最小值。

high :

允许的最大值。

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)

返回一个结构体指定偏移量的成员,使用指定类型

member_type :

结构体类型。

struct_p :

指向结构体的指针

struct_offset :

自结构体起始的偏移,字节类型。

Returns :

结构体成员。

G_STRUCT_MEMBER_P()

#define             G_STRUCT_MEMBER_P(struct_p, struct_offset)

返回一个结构体的既定偏移量的无类型指针。

struct_p :

指向结构体的指针。

struct_offset :

自结构体起始的偏移,字节类型。

Returns :

指向struct_pstruct_offset 个字节数的无类型指针。

G_STRUCT_OFFSET()

#define             G_STRUCT_OFFSET(struct_type, member)

返回偏移量,字节类型,结构体的成员。

struct_type :

结构体类型, e.g. GtkWidget.

member :

结构体的域。e.g. window

Returns :

struct_typemember的偏移量

G_MEM_ALIGN

#  define G_MEM_ALIGN GLIB_SIZEOF_VOID_P

Indicates the number of bytes to which memory will be aligned on the current platform.

指明当前平台内存对齐的字节数。


G_CONST_RETURN

#define G_CONST_RETURN

如果 G_DISABLE_CONST_RETURNS 定义了, this macro expands to nothing. 默认情况下,, the macro expands to const. The macro should be used in place of const for functions that return a value that should not be modified. The purpose of this macro is to allow us to turn on const for returned constant strings by default, while allowing programmers who find that annoying to turn it off. This macro should only be used for return values and for out parameters, it doesn't make sense for in parameters. 【不清楚这里如何理解】