Home ScienceComputer Science Subscribe to RSS

What Is The Difference Between An Inline Function And A Macro?

Answer Question

2 Answers - Sort by: Date | Rating

    A statement or a group statements(function) which are oftenly used in a program can be written in the form of a function whitch is nothing but a MACRO.

    eg:   #define  pi  3.14  

    It is a single line macro.If you want to use 3.14 any where in the program u can simply use 'pi', then pre processor assigns 3.14 to the 'pi' while exicuting a program.

    coming to IN LINE FUNCTION  it is also a macro,but it has aditional properties like

    1.if u write a big function as a inline function pre processor assumes it  like a normal function  (why  because  generaly inline functions or macros  are used to reduse the switching time between the functions)  automatically.That means while writing an inline function it is a request to the pre-processor but not an order.
    0 0

    Y4ec906  

    answered 3 years ago

      It's possible to define a macro to expand into the same code that an inline function would execute.  But the macro would be limited to direct use in expressions--a macro cannot be called with apply, mapcar and so on. Also, it takes some work to convert an ordinary function into a macro. To convert it into an inline function is very easy; simply replace defun with defsubst. Since each argument of an inline function is evaluated exactly once, you needn't worry about how many times the body uses the arguments, as you do for macros.
      0 1

      Vinodg2000  

      answered 3 years ago

        More

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International