-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstdelone_bonus.c
36 lines (33 loc) · 1.94 KB
/
ft_lstdelone_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oadewumi <oadewumi@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/11 15:00:45 by oadewumi #+# #+# */
/* Updated: 2023/12/13 11:38:03 by oadewumi ### ########.fr */
/* */
/* ************************************************************************** */
/* This function takes a parameter as a node and frees the memory of the
node's content using the function 'del' givern as a parameter also and
free the node. */
/* Although the memory of the next must not be freed. */
/* First of all we need to check if the function 'del' exists.
If it exists, then we write the function 'del', using parenthesis as (*del),
to delete the content of the node 'lst' like this (*del)(lst->content).
(this is a way, we use a typecast concept to the void 'del' function).
(In C, function pointers are called using (*functionPointerName)().
It dereferences the function pointer to call the function it points to.
In this case, (*del)(lst->content) is dereferencing the function pointer del
and passing lst->content as an argument to the function that del is pointing to.
The parentheses around (*del) are used to ensure that the function pointer del
is dereferenced before being called as a function.) */
/* Thus, we free the node 'lst' */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void*))
{
if ((*del))
(*del)(lst->content);
free(lst);
}