void run_hot(void) {
// I am called very often!
serve();
// <more code here>
}
void run_cold(void) {
// I am called only occasionally!
serve();
// <more code here>
}
???inline??? void serve(void) {
// I only want to be called inline from hot functions!
// <more code here>
}
Is there any way to explicitly inline a function A in a function B while explicitly not inlining the same function A in a function C? Or am I completely at the mercy of my compiler?
The compiler will not consider a function to be an inline function if it is recursive. If the function contains one or more static variables, the compiler will deny the request to make it an inline function.
The extern-inline module supports the use of C99-style extern inline functions so that the code still runs on compilers that do not support this feature correctly. C code ordinarily should not use inline .
Inline functions are commonly used when the function definitions are small, and the functions are called several times in a program. Using inline functions saves time to transfer the control of the program from the calling function to the definition of the called function.
Similarly, if you define a function as extern inline , or redeclare an inline function as extern , the function simply becomes a regular, external function and is not inlined.
You are completely at the mercy of the compiler with inlining.
Leave aside partially, whether or not to inline
a function is solely a decision that is best made by the compiler and you should rely on it to make the best decision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With