Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro method has 2 returns?

I've just moved over from Java to C++ and I've never used macros before and I'm confused how some methods seem to return two variables, such as

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)

or even stranger combinations like

JNIEXPORT jdoubleArray JNICALL Java_algorithms_Shuffle0_getPriorities (JNIEnv *, jobject, jint, jint).

Can someone tell me what's going on? Sorry if this seems like extreme ignorance, but as I say I've never used macros before and The Complete Reference to C++ chapter on the preprocessor doesn't make these arrangements any clearer.

like image 487
Ghost Avatar asked Apr 20 '26 02:04

Ghost


1 Answers

You need to expand each macro to fully understand it. Run your code through the pre-processor to see how it expands, or use your helpful IDE tools to show you.

When you do so you will see the following:

  • LRESULT is the result type. It's an integer of some description.
  • CALLBACK defines the calling convention which would be __stdcall.

And as for the other one:

  • JNIEXPORT probably expands to declspec(dllexport). This specifies that the function is to be exported from the library.
  • jdoubleArray is the return value.
  • JNICALL will be the calling convention.

You can think of these extra tokens as being decorators to the function. They do not change the signature of the function at a conceptual level. Probably the closest analogous concept in Java would be attributes.

like image 176
David Heffernan Avatar answered Apr 22 '26 18:04

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!