Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-01-2010
Member
 
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!!!!

Reply With Quote
  #2  
Old 25-01-2010
Member
 
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.
Reply With Quote
  #3  
Old 25-01-2010
Member
 
Join Date: May 2008
Posts: 2,286
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;
}
Reply With Quote
  #4  
Old 25-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,997
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.
Reply With Quote
  #5  
Old 25-01-2010
Member
 
Join Date: May 2008
Posts: 2,004
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "List the differences between macro and inline() : C++"
Thread Thread Starter Forum Replies Last Post
Information and use of macro for search the list of words Farhat007 Windows Software 4 06-09-2010 10:56 PM
Advantages of Inline Function Sonam Goenka Software Development 4 08-02-2010 10:07 AM
Don't know about an inline class Bottlenecked Software Development 5 25-01-2010 08:57 AM
What is the use of inline function Jabeen Software Development 3 19-11-2009 11:22 AM
Virtual inline in C++ Jacek Software Development 5 27-12-2008 11:57 AM


All times are GMT +5.5. The time now is 02:01 AM.