int32_t
¶Signed integers are the best types when you are dealing with a positive or negative integers.
The are generally useful in many contexts, for example when you want to keep the order of a series of states (each state stored as a given number in an enum
for example).
On many modern systems, int32_t
is just an alias for int
, so you can use them interchangeably.
To make sure, check the size of int
on your system:
struct
): gal_list_i32_t ¶A single node in a list containing a 32-bit signed integer (see Numeric data types).
typedef struct gal_list_i32_t { int32_t v; struct gal_list_i32_t *next; } gal_list_i32_t;
void
(gal_list_i32_t **list
, int32_t value
)
¶Add a new node (containing value
) to the top of the list
of int32_t
s (uint32_t
is equal to int
on many modern systems), and update list
.
Here is one short example of initializing and adding elements to a string list:
gal_list_i32_t *list=NULL; gal_list_i32_add(&list, 52); gal_list_i32_add(&list, -4);
int32_t
(gal_list_i32_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 also return GAL_BLANK_INT32
(see Library blank values (blank.h)).
size_t
(gal_list_i32_t *list
)
¶Return the number of nodes in list
.
size_t
(gal_list_i32_t *list
)
¶Return a pointer to the last node in list
.
void
(gal_list_i32_t *list
)
¶Print the integers within each node of *list
on the standard output in the same order that they are stored.
Each integer is printed on one line.
This function is mainly good for checking/debugging your program.
For program outputs, it is best to make your own implementation with a better, more user-friendly format.
For example, the following code snippet.
You can also modify it to print all values in one line, etc., depending on the context of your program.
size_t i=0; gal_list_i32_t *tmp; for(tmp=list; tmp!=NULL; tmp=tmp->next) printf("Number %zu: %s\n", ++i, tmp->v);
void
(gal_list_i32_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.
int32_t *
(gal_list_i32_t *list
, int reverse
, size_t *num
)
¶Dynamically allocate an array and fill it with the values in list
.
The function will return a pointer to the allocated array and put the number of elements in the array into the num
pointer.
If reverse
has a non-zero value, the array will be filled in the opposite order of elements in list
.
This function can be useful after you have finished reading an initially unknown number of values and want to put them in an array for easy random access.
void
(gal_list_i32_t *list
)
¶Free every node in list
.
GNU Astronomy Utilities 0.23 manual, July 2024.