0

Normally what a typedef does is

typedef DATATYPE NEW_NAME

However, the following is a bit complex and seems like mixing with some other concepts (like the tuple-alike guy)

typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);

Stephen Fong
  • 697
  • 5
  • 17
  • 1
    Please don't post images of text. – user2357112 Dec 13 '19 at 05:15
  • Does this answer your question? [Understanding typedefs for function pointers in C](https://stackoverflow.com/questions/1591361/understanding-typedefs-for-function-pointers-in-c) – ead Dec 13 '19 at 06:32

1 Answers1

1

The definition looks confusing since function pointers are confusing at first. The definition

typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);

Means “create a typedef named newfunc that is a function taking in a struct _typeobject* and two PyObject*s and returns a PyObject*. The name is after the return type in the middle like it would be with a regular function definition:

PyObject *somefunc(struct _typeobject *, PyObject *, PyObject *);

As it’s a function pointer it needs parentheses and another * to show it is a pointer and the datatype is around the name.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
  • why do we need (*newfunc) instead of newfunc? – Stephen Fong Dec 13 '19 at 08:26
  • @SamiKuhmonen so the syntax for function typedef is different to data type typedef? becuz here we're like defining a variable which accept a function as its value, and this function's prototype must match the type's definition – Stephen Fong Dec 13 '19 at 08:46