***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Posts

    Tuesday, November 24, 2020

    Inline Function

    C language provides a mechanism called inline function. The property of inline function is, compiler inserts the entire body of the function in the place where inline function call is used in the program.

     Using inline functions passing of control between function caller and function callee is avoided.

     A normal function becomes inline function when function prototype of the function is prepended with keyword “inline”.

     Inline function mechanism increases execution performance.

     Disadvantage of inline function is, it increases file size as same function code is copied again and again in the program wherever it is called.

     #include <stdio.h>

      // Inline function in C

     inline void sum(int x, int y)

    {

        int z;

        z=x + y;

        printf(“sum is %d”,z);

    }

    void main()

    {

     int x=5,y=6;

    sum(x,y); 

    }

     

    Following are situations where inline function may not work

    1. if the function is recursive.

    2. if the function contain static variables.

    3. if the functions contains control structure statements.

    4. and the function main cannot work as inline.

    No comments:

    Post a Comment

    Top