Function Macro


Declaration [src]

#define g_array_index (

Description [src]

Returns the element of a GArray at the given index. The return value is cast to the given type. This is the main way to read or write an element in a GArray.

Writing an element is typically done by reference, as in the following example. This example gets a pointer to an element in a GArray, and then writes to a field in it:

  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 ();

This example reads from and writes to an array of integers:

  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;


a -

A GArray.

t -

The type of the elements.

i -

The index of the element to return.