-
Notifications
You must be signed in to change notification settings - Fork 2
inline
Wu Jie edited this page Mar 30, 2014
·
1 revision
Linus explain the statice/extern inline as:
- “static inline” means “we have to have this function, if you use it but don't inline it, then make a static version of it in this compilation unit”
- “extern inline” means “I actually have an extern for this function, but if you want to inline it, here's the inline-version”.
You must be careful when using inline function in c/cpp, where inside the function there have a static variable. In this case, if you don't add decorate (extern or static) on the inline function, you will get warning message when compiling.
It is easy to explain this, because inline function may not be inline depends on the compiler optimization method and other things, so as linus said, extern inline function will share the static variable in all the code, but static inline will share it in same compile unit.
You can treat the behavior as function vs static function.