ENCYCLOPEDIA 4U .com



Encyclopedia Home Page

Google
  Web Encyclopedia4u.com

 

In-line expansion

The in-line expansion is a technique in generating target code that compilers expand actual implementation of subprograms in the point of calling them rather than calling a common chunk of code. It is a better solution to problems with use of lexical substitution of code, or macro. The main drawback is that the expansion usually results in a larger binary code, which can actually hurt performance if it affects locality of reference.

Often, use of in-line expansion over calling subprograms reduces overhead of subroutine calling dramatically. Unlike macro, the effect is semantically guranteeded to be equivalent to calling subroutines, though some subtle bugs may be introduced in some circumstances such as compiler bug. Besides, the definition of subroutines with the expansion is usually identical to the definition of ones without the expansion with certain comment about expansion except the statement indicating the subprogram should be inlined.

C++ is well known for its support over C. In Ada programming language, significant comment, or pragma states the subroutine should be expanded if possible. Because implementing this expansion is difficult to deal with polynomic subroutines, not many programming languages support it. Some Java runtimes (notably the HotSpot compiler) support aggressive inlining based on actual runtime call patterns; this is a "best of both worlds" solution, since they are the only inline parts that are frequently used. Mainstream C++ compilers like Micrsoft C++ or GCC supports the option that lets the compilers inline any small subprogram without any indication of the expansion even for C code.

A recursive subprogram usually cannot be expanded. Because it call itself recursively, if the compiler attempts to expand it, the compiler would generate infinite long code.

Subprogram with this expansion can be written in C++ like:

inline int
max (int a, int b)
{
 return a > b ? a : b;
}

max (x, y); // this is basically equivalent to "x > y ? x : y";





Content on this web site is provided for informational purposes only. We accept no responsibility for any loss, injury or inconvenience sustained by any person resulting from information published on this site. We encourage you to verify any critical information with the relevant authorities.



Copyright © 2005 Par Web Solutions All Rights reserved.
| Privacy

This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "In-line expansion".