#include <iostream>
usingnamespace std;
inlinevoid function_1()
{
cout<<"I am a function";
cout<<"\nand I am writing to console";
}
int main()
{
void function_1();
return 0;
}
same as when we say :
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
usingnamespace std;
int main()
{
cout<<"I am a function";
cout<<"\nand I am writing to console";
return 0;
}
it seems as a class or something
I read that an inline function is that it just prints\performs every thing between the { and } like as it was written inside the main() function of a program.
Inline function is a function that can be defined in a header, included into multiple source files and not cause a linker error.
function inlining (a type of compile-time optimization) hasn't depended on the keyword inline in ages: even without it the main() function will consist of the two calls to operator<< (or whatever that expands to) on any sensible compiler.
You cannot force the compiler to inline a particular function, even with the __forceinline keyword
why when using recursion some compilers ignores the inline
Compiler never ignores inline in its required meaning (allowing the function to be included in many source files). Optimizer may choose not to inline a recursive function depending on the contents of the function and the quality of the optimizer.
The inline keyword tells the compiler that inline expansion is preferred. However, the compiler can create a separate instance of the function (instantiate) and create standard calling linkages instead of inserting the code inline. Two cases where this can happen are:
* Recursive functions.
* Functions that are referred to through a pointer elsewhere in the translation unit.
Unless a recursive function undergoes tail-call optimization, and is therefore converted to a single function using a loop, the recursive call needs somewhere to go (i.e. an address) so the function cannot be inlined.