The inline function is a C enhancement designed to speed up execution of programs. The coding of normal functions and inline functions are similar except that inline function definition starts with the keyword inline. The distinction between normal functions and inline functions is the different compilation process.

Working: After writing any program, it is first compiled to get an executable code, which consists of a set of machine language instructions. When this executable code is executed, the operating system loads these instructions into the computerís memory, so that each instruction has a specific memory location. Thus, each instruction has a particular memory address.

After loading the executable program in the computer memory, these instructions are executed step by step. When the function call instruction is encountered, the program stores the memory address of the instructions immediately following the function call statement; loads the function being called into the memory; copies argument values; jumps to the memory location of the called function; executes the function codes; stores the return value of the function and jumps back to the address of the instruction that was saved just before executing the called function.

The C inline function provides an alternative. With inline code, the compiler replaces the function call statement with the function code itself (process called expansion) and then compiles the entire code. Thus, with inline functions, the compiler does not have to jump to another location to execute the function and jump back because the code of the called function is already available to the calling program. Example:

inline void max(int a, int b)
  return (a > b ? a : b);
int main()
  int x = 10, y = 20, z;
  z = max(x, y);

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.