4 ms·
Both of these implementations seem to be missing a call to `free`, or is that something that the caller should be taking care of?
by jamesdsadler 6y ago
Both of these implementations seem to be missing a call to `free`, or is that something that the caller should be taking care of?
- Arnavion 6y agoIt's pseudocode. The code as-is is not valid C anyway.
- rightbyte 6y agoNow you are assuming "remove_list_entry" is not a macro!
- jagged-chisel 6y agoDepends on whether the list owns the nodes. I tend to write mine such that it does. Perhaps this code is demonstrative rather than complete.
- arka2147483647 6y agoThe caller could want to move the element from one list to another, in which case the optimum impl would not free or copy the element.
- eperdew 6y agoAs others have said, often you don't want to free the node, you want to do something else with it. E.g., put it in a free list. However, usually if you're not freeing it, you'd null out the next field so that you don't accidentally access it when it's not part of the list (at least I would).
- scoutt 6y agoWhy do you think the values were allocated in the heap?