1

The declarations related to the question are are :

typedef void (*struct_c)(
    pid_t,  
    const uint_t *,
    struct_a,       
    struct_a,       
    void *);

void func1(struct_a s, struct_a e, struct_d init, struct_c range, struct_e fini, void *arg);
static void add_range(pid_t mgid, const uint_t *propids,struct_a s, struct_a e, void *arg);

There is a function call as follows:

func1(s, e,NULL,add_range, NULL, &ranges);

The argument add_range is a function name, there is no other variable by that name.

I don't understand how the function call func1 works and what are its arguments.

If you need more details,let me know.

Iceman
  • 365
  • 1
  • 3
  • 13

2 Answers2

3

struct_c is a function pointer

void func1(struct_a s, struct_a e, struct_d init, struct_c range, struct_e fini, void *arg); says

contains the function pointer in its 3rd argument i.e. struct_c range which matches the prototype of the function pointer

typedef void (*struct_c)(
    pid_t,  
    const uint_t *,
    struct_a,       
    struct_a,       
    void *);

and the prototype of the add_range function.

static void add_range(pid_t mgid, const uint_t *propids,struct_a s, struct_a e, void *arg);

In a trivial sense,

Function pointers are to functions, as, integer pointers are to integers or such.

askmish
  • 6,464
  • 23
  • 42
2

struct_c is a type that is a pointer to function.

When calling func1 the add_range, given that it has an appropriate signature, is implicitly converted to the required function pointer.

It is probably a poor choice of name though, I can only imagine there is legacy here.

Niall
  • 30,036
  • 10
  • 99
  • 142
  • I understood that, but my question is when you call func1 like this `func1(s, e,NULL,add_range, NULL, &ranges);` What are the arguments of add_range? Shouldn't the call to func1 be like `func1(s, e,NULL,add_range(1,2,var_a,var_a,NULL), NULL, &ranges);` – Iceman Jul 28 '14 at 15:01
  • 1
    @Anurag, nothing yet (as you call `func1`). The `func1` just wants a pointer to an appropriate function. It will presumably call the function with the arguments it calculates or has (from some or other source). – Niall Jul 28 '14 at 15:07