inline funcitons = written code ?

Hello

is this code is really almost same as this? :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #include <iostream>
  using namespace std;
  inline void 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>
  using namespace 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.

Last edited on
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.
Last edited on
there is force_inline function in ms vs 2010
and why when using recursion some compilers ignores the inline

Even __forceinline is only a (strong) suggestion: http://msdn.microsoft.com/en-us/library/z8y1yy88(v=vs.110).aspx
MSDN wrote:
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.
From the MSDN article Cubbi provided the link to:

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.


inline, __inline, __forceinline
http://msdn.microsoft.com/en-us/library/z8y1yy88%28v=vs.110%29.aspx

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.

Andy
Topic archived. No new replies allowed.