Reputation: 473
I know my C up to this point. I was looking at the source files of PHP I downloaded, and I saw this strange syntax:
PHPAPI int php_printf(const char *format, ...)
{
// code...
}
What does the PHPAPI
do before the return type int
? I've tried searching all over and I can't understand what this means. Is it a second return type? It can't be because the function does return an int. Maybe it extends to some other struct declared in a header file?
Upvotes: 3
Views: 288
Reputation: 41002
Go to the makefile and add in the line that compiles the sources: -E
, by doing so you will see the source cose after the preprocessing phase.
Search all the project for PHPAPI
:
find it in php.h:
#ifdef PHP_WIN32
#include "win95nt.h"
# ifdef PHP_EXPORTS
# define PHPAPI __declspec(dllexport)
# else
# define PHPAPI __declspec(dllimport)
# endif
#define PHP_DIR_SEPARATOR '\\'
#else
#define PHPAPI
#define THREAD_LS
#define PHP_DIR_SEPARATOR '/'
#endif
Now what you need to know is what is __declspec(dllexport)
and what is __declspec(dllimport)
In the SO thread- What is __declspec and when do I need to use it?
The canonical examples are
__declspec(dllimport)
and__declspec(dllexport)
, which instruct the linker to import and export (respectively) a symbol from or to a DLL.// header __declspec(dllimport) void foo(); // code - this calls foo() somewhere in a DLL foo();
(
__declspec(..)
just wraps up Microsoft's specific stuff - to achieve compatibility, one would usually wrap it away with macros)
Upvotes: 5