Let's say I have a function:
t_list *get_first_matching(t_list *head_of_list, <some other stuff>);
This function would retrieve an element from the given list and I would be able to modify it.
But if I have something like this:
void print_matching(const t_list *head_of_list)
{
const matching_elemnt = get_first_matching(head_of_list, <other stuff>);
<print the element>
}
The compiler will say that that I can't pass a constant pointer to that function.
What I could do, is copy paste that function, adding const:
const t_list *get_first_matching(const t_list *head_of_list, <some other stuff>);
Can I make only one function that would work with const parameters and would also work in case I would need to modify the retrieved element?
Is there a solution without warnings or without const cast?