I’m just learning C language, and knew how to write a function:
return_type function_name() {}
It seems that only one return type could been written at definition, however, I seen some styles in Win32 API and Android JNI cound also been compiled successful:
LRESULT CALLBACK WindowProc()
JNIEXPORT void JNICALL Java_ClassName_MethodName()
I’m confused why they are two or three return types. I searched and found these may be modifiers, but what I learned the modifiers should be static
, long
, unsigned
those keywords.
>Solution :
CALLBACK
, JNIEXPORT
and JNICALL
are not types; those are macros that may expand to some platform-specific language extensions to declare some other properties of the function.
In this case, CALLBACK
and JNICALL
are used to declare the calling convention for those functions. JNIEXPORT
will be used to mark that the function is exported (when building the library) or imported (when linking against the library) when dynamic linking is used.
These details are necessary to provide libraries with stable ABI (Application Binary Interface). These details are, however, outside the scope of the C standard. They also depend on the platform and configuration that the library is built on. Therefore library writers resort to using macros that expand to the appropriate platform-specific syntax depending on the scenario that the code is compiled in.