arun2802 arun2802 - 1 year ago 78
C Question

How do you call functions with __P in the prototype?

I have been going through some header files and see that there are many function prototype like this:

returntype some_name __P(arguments);

If I were to call this function how do I do it? Do I use something like


excluding the
, or is there some other way to call such functions?

Answer Source

This kind of prototype uses a macro __P to allow inclusion and compilation on very old systems that do not support C90 prototypes (aka ansi prototypes).

On most systems, the argument to the __P macro expands to the argument list, as illustrated below:

#define __P(args)  ()
#define __P(args)  args

int some_name __P((int argc, char *argv[]));

On obsolete systems, the above declaration expands to int some_name(); whereas it expands to the full prototype otherwise: int some_name(int argc, char *argv[]);

Just ignore the __P macro and use some_name(arguments); syntax to call the function. Also note that the macro name __P is not significant, the author of the package could have used any name for this purpose.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download