passing data structures to function pointers and get there values

Sep 26, 2014 at 7:57pm
hi all,
please see this example and say what should i do
1
2
3
4
5
6
7
8
9
10
typedef struct example_dt_struct {
int a;
float b;
char* c;
};
typedef void(*func)(example_dt_struct *s, int e, int f);
void f(func *n)
{

}

how can i use example_dt_structure with my function pointer into f()
thanks in advance
Last edited on Sep 26, 2014 at 7:59pm
Sep 26, 2014 at 8:07pm
1
2
3
4
5
void f(func *n)
{
    example_dt_struct foo;
    n(&foo, 0, 0);
}
Sep 26, 2014 at 8:22pm
ok, how can i access foo.a or foo.b or foo.c?
Sep 26, 2014 at 8:26pm
through the passed pointer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void some_function(example_dt_struct *s, int e, int f)
{
    s -> a = e;
}

void f(func *n)
{
    example_dt_struct foo;
    n(&foo, 0, 0);
}

int main()
{
    f(some_function);
}
Sep 27, 2014 at 2:58am
ok, how can i access a variable in a function type?
for example, from a function, get access to a parameter of a typedef?
Sep 27, 2014 at 5:41am
In my example func is a typedef.
Topic archived. No new replies allowed.