0
typedef void (*Hello)(struct test1 *, test2 *, int a, int b, const int c *, int d);

In this case, I am confused by how to handle the struct as the argument.

I have written:

Hello p1;
(*p1)(....need some arguments to be added here);

Please kindly teach me how to complete this maybe sample code could help.

Thanks

user3815726
  • 520
  • 2
  • 6
  • 20
  • 1
    Start with a simpler `typedef`, say with one argument. Then add more arguments as you get familiar and more confident of how it works. – R Sahu Jun 18 '15 at 03:53

1 Answers1

1

Here is some code

struct point {
  int x;
  int y;
};

typedef void (*Hello)(struct point *p);

void resetPoint(struct point *p)
{
  p->x = 10;
  p->y = 0;
}

int main(void)
{
  struct point dot;
  Hello p1 = resetPoint;
  p1(&dot);
  printf("%d\n",dot.x);
  return 0;
}
Filip Bulovic
  • 1,776
  • 15
  • 10
  • Thanks Filip. What really confuses me is that how I can fill strcut test1 * as an argument in this function. Would you mind show me the snippet? – user3815726 Jun 18 '15 at 04:46
  • Sure, inside main `struct point dot;` then `resetPoint(&dot);` if you are using typedef Hello, then `Hello p1 = resetPoint;` and `p1(&dot);` – Filip Bulovic Jun 18 '15 at 04:59
  • would you please update your answer so that I can avoid misunderstanding what you mean. – user3815726 Jun 18 '15 at 05:32