Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is difference between macro and inine function.?
Posted

Macros are processed by the C/C++ preprocessor before the compilation is performed.

Inline functions are like normal functions, but the compiler will not generate a single block of code that is called each time the function is used. Instead, the compiler inserts the function code whenever the function is used.

An example:
C++
#define DIV_BY_TWO(a)  ((a) >> 1)
inline int DivByTwo(int a) { return a >> 1; }
int DivByFour(int a) { return a >> 2; }

int i = 8;
int j = 0;
// The preprocessor replaces this line by
// j = ((i) >> 1);
// which is then passed to the compiler.
j = DIV_BY_TWO(i);

// The compiler generates code using 
// i >> 1
j = DivByTwo(i);

// The compiler generates a call to the function DivByFour
j = DivByFour(i);
 
Share this answer
 
If we talk about c or c++ than macros are the simple codes which are declared with header files and which are fixed like
# macro Pi=3.14;

on the other hand inline functions are the functions which are used to call a function again and again in a class or a specific code body but this functions increases the memory use of programs. Simply a keyword "inline" is used in front of the function to make them a inline function.




Edit: SQL-Code tags deleted
 
Share this answer
 
v2
Comments
bchandu06 18-Jun-12 13:55pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900