Next: Ordered list of size_t, Previous: List of double, Up: Linked lists [Contents][Index]
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”.
struct
): gal_list_void_tA 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;
**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 *vlist=NULL; gal_list_f64_add(&vlist, some_pointer); gal_list_f64_add(&vlist, another_pointer);
**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
.
*list
)Return the number of nodes in list
.
*list
)Return a pointer to the last node in list
.
**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.
*list
)Free every node in list
.
Next: Ordered list of size_t, Previous: List of double, Up: Linked lists [Contents][Index]
GNU Astronomy Utilities 0.13 manual, September 2020.