Alex Rivera | Logout

How can I create a function that takes a parameter of unknown type in C?

Asked 2011-05-17T09:30:24.817
12

Say I have the following code:

struct test* t1;
t1 = get_t(1);

... where get_t is:

struct test* get_t(int);

How can I refactor the above code and put it in a function? Something like the following:

void r1(?* t, ?* (fn*)(int)) {
    t = fn(1);
}

/* ... */

struct test* t1;
r1(t1, &get_t);
Edit
Report

1 Answer

4

use void *param, a pointer to anything ... commonly used in glib as gpointer

answered 2011-05-17T09:33:15.757

Your Answer