When reading Enlightenment’s code, I found some things about C I don’t understand. I’ll paste the lines and explain why its not clear to me.
Eina_Bool (*hide)(void *data, Evas_Object *o);
void (*del)(void *data, Evas_Object *o);
On this ones, what do that pointer values between parentheses means just after return value?
Also, notice that the first parameters of both functions is void *data. Does that mean you can pass a pointer to any type of data to the function?
EAPI Ecore_X_Window elm_win_xwindow_get(const Evas_Object *obj);
Almost all functions on the API starts with EAPI. What does that mean? Is it a kind of namespaces? Where can I find some info about that?
Also notice how they use one of it’s libraries: Elementary.
EAPI_MAIN int elm_main(int argc, char **argv) {
// CODE
}
ELM_MAIN()
Instead of using a main function, you use that elm_main with again those uppercase flags: EAPI_MAIN.
And just after the function there is that weird ELM_MAIN() without semicolons.
I’ll appreciate if you guys explain me a bit about all this that seemed strange the very first time I saw them.
Note: All of the examples I pasted came from elm_win.h Elementary header.
The lines that you show here are declarations of function pointer variables.
A line of the form:
for example declares a variable called foo that can hold (the address of) a function that takes one integer argument (
x) and returns an integer. If you declare a function like this:you could assign (the address of) that function to the variable foo.
and then you could call the function
twicethrough the pointer:(
resultwould now contain 6)The usual reason to so something like this is that you know you want to call some function at a certain point in the code, but exactly what function depends on other code. If you had functions called
process_Aandprocess_Byou might assign one of them to a function variable:here the result is set to the value calculated either by
process_Aor byprocess_B, depending on which one was assigned toprocessYou could use a conditional at the point of call, of course, but selecting the function and storing it (or rather its address) in a variable leads to more efficient and (more importantly) clearer code.
As for the
EAPIsymbol … I don’t know Enlightenment, but I would expect that that is just a macro #defined in a header. It probably changes the calling convention or exports symbols depending on the build options.