简体   繁体   中英

Inline Functions - Automatic inline

When a short function is defined inside a class declaration, it is automatically made into an inline function.

My questions are,

  1. How short the function should be for automatically in-lining ? Is there any line-limit for that?
  2. Is there any way to know that a function is automatically in-lined ?
  1. How short the function should be for automatically in-lining ? Is there any line-limit for that?

There is no hard limit (or more precisely yes, we can find upper limit on a given system but you won't find it specified anywhere). The compiler tries to predict what the advantages of this process given particular circumstances might be. If the compiler decides that inlining the function will make the code slower, or unacceptably larger, it will not inline it. It won't do it also if it simply cannot do it because of a syntactical dependency, such as other code using a function pointer for callbacks, or exporting the function externally as in a dynamic/static code library. Remember also that marking function inline is only expressing a wish, compiler is not obliged to do this. In C, any function with internal linkage can be inlined, but a function with external linkage is subject to restriction.

  1. Is there any way to know that a function is automatically in-lined ?

You can disassemble the binary and you will see if there is an call to a function or if it is in line .

Do inline functions improve performance?

Inline Functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM