These lines are pointers to functions, I have answered with more detail in Use a void function as a parameter of another. The void
and the uchar
are return types as occurs in any other function. And the fact of being within a struct
does not change anything, only you have variables to save the pointer to the function, but are still normal functions, only the access will be indirect. Has a another example. And another example.
This is a form of indirect for calling a function, then you create a pointer to an address where the function is (the body of the function will be elsewhere), then you can store in a variable that pointer value, in this case the variable is within a struct
. Changing the value will access a different function, and this is powerful to give flexibility and let decide what to call at runtime.
Actually this mechanism used in this way is something like polymorphism that you might know about object orientation. It is possible to program OO in C using precisely this capability. When you use a language natively OOP internally this is what it does, only you don’t see, in C you see and manipulate in hand.
If it is not clear, the second block of parentheses are the function parameters. So in this case taking the example you can at some point in your code tell what is the function to be called by placing its address in the variable ThrowException
inside the object you are manipulating that is of the WNMEnv_
. So when you create the object you configure what should be called. Somewhere the called function will come from what is in ThrowException
, probably this call is already within the infrastructure of what you are using, is part of the internal implementation of this API, you just configure what will be run.
If you know any other more abstract language you can compare with lambda or anonymous function. Internally that’s how it works, even in those languages. We also call it callback.
To better understand it would be interesting to take a chunk of code that has the use of this or an object example created and configured for use of this.
That’s another question but come on, people use _
to avoid any conflict of new, in general the team chooses a convention that names with it have a special meaning, so do not mix with other names that may need to be equal.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero