About __forceinline and __inline

Asked

Viewed 112 times

3

What is the difference between using __forceinline or __inline? And you can use __forceinline or __inline large-scale?

Example:

__forceinline void funcao1(void)
{
    cout << "Funcao 1" << endl;
}

__inline void funcao2(void)
{
   cout << "Funcao 2" << endl;
}
  • 1

    Remembering that __forceinline and __inline are specific to Microsoft compilers and are not part of the standard C98. Only the keyword inline is part of the pattern C98 and C++.

1 answer

2


These instructions indicate to the compiler that you want the function to be linearized, i.e., that instead of calling it its code is placed where it had a call saving a few bytes and processing since it is no longer necessary to have the function header and footer and in some cases no longer need to copy argument data to parameter.

inline is standard of C++ and is a hint for the compiler to consider doing this optimization there. Not that he does not do if he does not have this keyword, he can do if he thinks it pays to optimize, even without anything written. Instructing like this can increase the chance, but depends on the compiler, nothing guarantees. Naga ensures that optimization is done, the compiler can recur if he doesn’t think it pays.

__inline is the same but is an extension of the Microsoft compiler. The exact way the compiler treats depends only on it.

__forceinline It’s just an indication that you really want the optimization to be done, so the chance is grid to occur, but it’s also not guaranteed. If it is too clearly bad the compiler does not.

Being able to use large functions can, but is not recommended and is likely to ignore the compiler. If you don’t know if it’s really useful, don’t use it, it’s a very advanced feature.

Documentation.

Related:

  • Thank you so much for the reply, it was extremely clear your explanation, now finally I understood why some functions of mine generated an error when compiling.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.