Results 1 to 5 of 5

Thread: List the differences between macro and inline() : C++

  1. #1
    Join Date
    Dec 2009
    Posts
    22

    List the differences between macro and inline() : C++

    Hi, Everybody. I studying in the BscIT first year. We have the C++ language in the syllabus for semister-2. I have the knowledge of C++ language, but I don't know about the Macro's and Inline functions of C++ language. So, I would like to know about the Macro's and Inline functions. I would also like to know about the what is the major difference between Macro's and Inline function. So, Anyone is there who can help me to find out the difference between the Macro's and Inline Function. I am waiting for your reply!!!!

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Macro and Inline()

    Hello, I think Inline function is function that is provided by C++ language. Inline function can be declared by using the keyword inline before the prototype of function. Macro is a preprocessor directive that is provided by C. Macro can be declared by using the " #define " preprocessor directive before the actual statement. Macro Preprocessor is very good for declaring constant variable for eg. #define PI 3.14. Macro provides textual substitution for the argument.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    List the differences between macro and inline()

    Inline functions follow all the protocols of type safety. In Inline function argument types are checked and conversions that are performed correctly. The compiler performs return type checking and function signature before putting inline function into symbol table. Inline function can be overloaded to perform the right kind of operation for the right kind of data. Hence, Macros are more error prone as compared to Inline functions. In No error checking is done during compilation. For Example :
    #define MAXI(p, q) ((p < q) ? q : p)
    int main( void)
    {
    cout << " Maximum of 20 and 30 is = " << MAX("30", "20") << endl;
    return 0;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: List the differences between macro and inline() : C++

    Same as like the regular functions Inline functions pass arguments by value. If the argument is an expression such as 5.5 +8.5 then the Value of the expression that the function passes is 14 in this case. Expressions that are passed into macros can not be always evaluated before entering into the macro body. Macros doesn’t pass by value. So, #define square(y) y*y : c=square(5.5+8.5). This will be replaced by : b=5.5+8.5*5.5+8.5. I hope you understood from the above explanation.

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: List the differences between macro and inline() : C++

    Inline functions can or can not be expanded by the compiler. Then It can be the compiler’s decision that whether to expand the function inline or not. Inline function can be defined outside or inside the class. Inline function can be used for debugging a program as they can be expanded at compile time and a break point could be placed at the Inline function a definition and they can be step into the method for step by step debugging. Macros can be always expanded. Macros can't be defined inside of the class. As they can be expanded at pre-compile time then they can't be used for debugging.

Similar Threads

  1. Information and use of macro for search the list of words
    By Farhat007 in forum Windows Software
    Replies: 4
    Last Post: 06-09-2010, 10:56 PM
  2. Advantages of Inline Function
    By Sonam Goenka in forum Software Development
    Replies: 4
    Last Post: 08-02-2010, 11:07 AM
  3. Don't know about an inline class
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 09:57 AM
  4. What is the use of inline function
    By Jabeen in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 12:22 PM
  5. Virtual inline in C++
    By Jacek in forum Software Development
    Replies: 5
    Last Post: 27-12-2008, 12:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,556,602.02171 seconds with 17 queries