top | item 25327528

(no title)

jamesdsadler | 5 years 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?

discuss

order

arka2147483647|5 years ago

The 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.

Arnavion|5 years ago

It's pseudocode. The code as-is is not valid C anyway.

rightbyte|5 years ago

Now you are assuming "remove_list_entry" is not a macro!

eperdew|5 years ago

As 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).

jagged-chisel|5 years ago

Depends on whether the list owns the nodes. I tend to write mine such that it does. Perhaps this code is demonstrative rather than complete.

scoutt|5 years ago

Why do you think the values were allocated in the heap?