Cruisehu Cruisehu - 2 months ago 5
C Question

Function Pointer Declaration - what does __P do?

The usual form of function pointer definitions is:

int function(int, int);
int (*ptr)(int, int);

but I saw a form today which I didn't understand. Can anyone explain this please?

int (*close) __P((struct __db *));


The __P() macro is usually used to support C implementations from the days of K&R C, when there were no prototypes (which were introduced to C with C89). Basically the logic is

#  define __P(argument_list) argument_list
#  define __P(argument_list) () 

Can you see how this works when applied to your example? Note that for this to work and not cause a syntax error, the argument list must include the parentheses of the function call, not just the parentheses of the function-like macro. Hence the double parentheses when the macro is used. That's probably the reason why it looks unusual.