Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between macro define functions and inline functions

Status
Not open for further replies.

tekdev

Programmer
Feb 12, 2003
3
IN
Hi to All
one way to declare function is macro
forexample
#define sqr(x) (x*x)

and other way is to make function inline in both cases, processor will replace the call by actual body of the function before compile and than process the code.
Now I want to know what the difference between in these two declaration.

tnx in advance
tekdev
 
WHat you said is true but the issue comes in when you do looping/recursion in an inline function. I would not want my fibonacci sequence to be inlined :)

Matt
 
Zyrenthian,
thanks! Could you explain a little more, though? I can't really see how a recursive function could be inlined or macrod, since every time the compiler hits the call to the recursive function it will start writing a new instance of the code... ad infinitum. How do macros and inlines differ in this (or don't I have to worry about it anyway)??
Thanks
 
hi,

i think inlining a function in 'C' is not supported. That support is with 'C++' compiler.

Secondly even if the function is inline, the inlining is done at the time of compilation unlike the #define macro where the text replacement is done before compilation.

sanjay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top