函数宏
GLibarray_index
声明 [src]
#define g_array_index (
a,
t,
i
)
说明 [src]
返回 GArray
中给定索引处的元素。返回值强制转换为给定类型。这是在 GArray
中读写元素的主要方式。
写入元素通常通过引用完成,如下面的示例所示。此示例获取对 GArray
中元素的指针,然后写入该元素中的某个字段
EDayViewEvent *event;
// This gets a pointer to the 4th element in the array of
// EDayViewEvent structs.
event = &g_array_index (events, EDayViewEvent, 3);
event->start_time = g_get_current_time ();
此示例从整数数组中读取并写入数据
g_autoptr(GArray) int_array = g_array_new (FALSE, FALSE, sizeof (guint));
for (guint i = 0; i < 10; i++)
g_array_append_val (int_array, i);
guint *my_int = &g_array_index (int_array, guint, 1);
g_print ("Int at index 1 is %u; decrementing it\n", *my_int);
*my_int = *my_int - 1;
此函数不直接对语言绑定可用。