Compilers
Which pair gives the advantage and drawback of function inlining?
- AAdvantage: smaller code. Drawback: more call overhead
- BAdvantage: faster compilation. Drawback: program results may change
- CAdvantage: no call overhead. Drawback: larger code
Show answer and explanation
Answer: C. Advantage: no call overhead. Drawback: larger code
Inlining embeds the function body in place of the call, eliminating argument passing, branching and returning. A major benefit is that constants from the caller flow into the body, enabling constant folding and dead-code elimination. On the other hand, each call site gets its own copy, enlarging the code and sometimes increasing instruction-cache misses, so it is applied selectively to small or frequently called functions. Done correctly, it does not change program results.
- A. Code actually grows, and call overhead shrinks.
- B. Done correctly, results do not change.
- C. Correct. Call overhead disappears and optimization broadens, but code grows.