Answer the question
In order to leave comments, you need to log in
How can I add this code to header and use it in other code?
Hello. There is this code:
// TODO: Add this to header (if apps really need it)
struct android_app *GetAndroidApp(void)
{
return CORE.Android.app;
}
Answer the question
In order to leave comments, you need to log in
Let's go in order.
In the presented example, we have a function implementation that takes no parameters and returns a pointer to the android_app structure - this is the type returned by the function;
GetAndroidApp - function name;
The construction after the name means that the function has no arguments, modern compilers allow you to write just empty brackets ;
In curly brackets write the body of the function, that is, its implementation.
C compilers read code from top to bottom, only what is declared above can be used. In addition, some entities can generally be compiled separately and then linked into 1 executable file.
struct android_app *
To do this, the C language supports entity declarations without their implementation, provided that the entity will be implemented below or somewhere else that is linked on the assembly.
For functions, the declaration (they also say the title) is a description of its signature, that is, for GetAndroidApp, this title will be:
// описание структуры android_app должно быть выше заголовка его использующего,
// иначе он будет невалидным. А вот описание полей (реализация) может быть и ниже
struct android_app;
struct android_app* GetAndroidApp();
comments says i can add it to HeaderThis means that these signatures can be placed in a header file (the one with the .h extension), this will allow you to insert it into many sources through the #include preprocessor directive
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question