Will
Will

Reputation: 2121

Can I inline a function partially/selectively?

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?

Upvotes: 6

Views: 240

Answers (1)

Alok Save
Alok Save

Reputation: 206546

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.

Upvotes: 4

Related Questions