This question really depends on whose responsibility it is to clear the entries in the list. If your structure is responsible for clearing the memory referenced by the void * fields, then you have a much bigger problem, namely, when specifying void * referring to any arbitrary block of memory, you will never know how to free it correctly . For example, if you have a dynamic array implementation along the lines of C ++ std::vector , then your void * may point to a structure that itself contains a pointer, and your list should know that it must go down to this structure in order to recursively release your dynamically allocated block. The case that you describe where you go into the nested list is just a special case of this more general problem.
If, on the other hand, the list is not responsible for clearing the memory referenced by void * that it stores, then you should not worry about this problem at all.
If your list has property semantics and you want to clear the memory for the items stored in it, I would strongly discourage you from using a magic number to determine if you have a nested list. Most likely, you should probably provide the client with a function pointer containing the maladaptation procedure to run the items inserted into the list. That way, your code can use a user-provided cleanup code to clear all the items stored in the list.
templatetypedef
source share