0

Let's say I have a function del that I want to call as argument of a function use_del in another function my_funct, like this :

void del(void *d);
void use_del(char *str, void (*del)(void *));

void  my_funct(void)
{
    // code
    char *str = "thing"

    use_del(str, (*del));

    // code
}

I sometime have an error message saying I should do use_del(str, (*de)(str)); but it sounds counter intuitive to me, since I'm supposed to call a function, not pass an argument to it.

Is the big block of code the correct use of a function pointer used as an argument ? I couldn't find resources on the subject beyond genericity, and I still struggle to make tests on specific parts of a code.

Jaune
  • 343
  • 1
  • 8
  • 2
    Inside `use_del()`, make the call using the pointer in either the old-fashioned way `(*del)(str)` or the new-fangled (only 30 years old) way `del(str)`. In `my_funct()`, pass just `del` as the parameter to `use_del()`. Beware shadowing — the parameter name `del` in `use_del()` shadows (hides) the public function name `del()`. – Jonathan Leffler Oct 14 '19 at 08:11
  • Perfect, thanks a lot and sorry for the duplicate – Jaune Oct 14 '19 at 09:17

0 Answers0