GNU Astronomy Utilities



12.3.8.6 List of void *

In C, void * is the most generic pointer. Usually pointers are associated with the type of content they point to. For example, int * means a pointer to an integer. This ancillary information about the contents of the memory location is very useful for the compiler, catching bad errors and also documentation (it helps the reader see what the address in memory actually contains). However, void * is just a raw address (pointer), it contains no information on the contents it points to.

These properties make the void * very useful when you want to treat the contents of an address in different ways. You can use the void * list defined in this section and its function on any kind of data: for example, you can use it to keep a list of custom data structures that you have built for your own separate program. Each node in the list can keep anything and this gives you great versatility. But in using void *, please beware that “with great power comes great responsibility”.

Type (C struct): gal_list_void_t

A single node in a list containing a void * pointer.

typedef struct gal_list_void_t
{
  void *v;
  struct gal_list_void_t *next;
} gal_list_void_t;
Function:
void
gal_list_void_add (gal_list_void_t **list, void *value)

Add a new node (containing value) to the top of the list of void *s and update list. Here is one short example of initializing and adding elements to a string list:

gal_list_void_t *list=NULL;
gal_list_f64_add(&list, some_pointer);
gal_list_f64_add(&list, another_pointer);
Function:
void *
gal_list_void_pop (gal_list_void_t **list)

Pop the top element of list and return the value. This function will also change list to point to the next node in the list. If *list==NULL, then this function will return NULL.

Function:
size_t
gal_list_void_number (gal_list_void_t *list)

Return the number of nodes in list.

Function:
size_t
gal_list_void_last (gal_list_void_t *list)

Return a pointer to the last node in list.

Function:
void
gal_list_void_reverse (gal_list_void_t **list)

Reverse the order of the list such that the top node in the list before calling this function becomes the bottom node after it.

Function:
void
gal_list_void_free (gal_list_void_t *list)

Free every node in list.