# Quiz1 of Computer Architecture (2025 Fall) ## Problem `A` 1. What's the benfits of using indirect pointer to the void? - According to [ISO/IEC 9899:TC3](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf). A pointer to void (`void *`) can be pointed to a variable of any data type. - [6.3.2.3] A pointer to void may be converted to or from a pointer to any incomplete or object type. - By utilizing indirect pointer to void (`void **`) allows `vector_t` holds diffenent types of data in the same array. 2. The meaning of `typedef void (*vector_delete_callback_t)(void *);`. - function pointer. - It is an **action** that can be passed as parameters and invoked inside a for loop. 3. Is there another way to implement the `vector_delete_all` function without `vector_pop`? - Pass the delete callback function to `vector_for_each`, and reset the `v->size` and `v->count` to zero after that. - [Glib](https://gitlab.gnome.org/GNOME/glib/-/blob/main/glib/glist.c#L1001) provides an implementation of `g_list_foreach` in a similar manner. In `g_list_free_full`, the foreach function is used to free the contents of the list object. ```c=158 void g_list_free_full (GList *list, GDestroyNotify free_func) { g_list_foreach (list, (GFunc) free_func, NULL); g_list_free (list); } ``` ```c=1001 g_list_foreach (GList *list, GFunc func, gpointer user_data) { while (list) { GList *next = list->next; (*func) (list->data, user_data); list = next; } } ``` ```c=141 typedef void (*GFunc) (gpointer data, gpointer user_data); ```