Compilers

Which pair gives the advantage and drawback of function inlining?

  1. AAdvantage: smaller code. Drawback: more call overhead
  2. BAdvantage: faster compilation. Drawback: program results may change
  3. 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.
Practice this topic Back to topic

More Compilers questions

  1. What is the main effect of loop unrolling?
  2. In the loop above, which computation is a candidate for loop-invariant code motion (hoisting out of the loop)? (Assume x and y are not modified in the loop.)
  3. In the loop above, which transformation applies strength reduction to the index computation i * 4?
  4. Why is the loop above hard to vectorize with SIMD instructions?
  5. In the function above, why can the compiler not simply hoist the load of *b out of the loop?