Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why function definition has multiple return types in C

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading