Re: Is there stack associated when a executing an inline function?



Mahesh wrote:

Hi,
I need to know if stack frames are generated in case of a
inline function execution or do they execute just like macros?

Normally, when a function's code is inlined, stack frames won't be
generated. The purpose of inlining is to avoid the costs associated
with a machine level function call and it's supporting code.

if they execute like macros, then what is the need for having
inline function?

One major advantage (and sometimes a major disadvantage) is the type
checking you get with inline functions. Macros are simply text
substitution and as such the later phases of the compiler aren't even
aware of their existence.

where would you use macros and where inlines?

Inline is just a hint to the compiler, which it is free to ignore.
Therefore if you need to be *sure* that the code must be duplicated at
each call site, then use macros. Also macros are necessary when you
want to simulate a crude form of generic code like C++'s templates.

One more fact to note is that the *inline* keyword is new to C99, which
has not been fully implemented by many C compilers. You can work around
this by testing the __STDC_VERSION__ macro and defining *inline* to
nothing if the former is less than 199901L. But very old compilers may
not define this macro at all, so be warned.


.



Relevant Pages

  • Re: How to get name of calling function
    ... > function to also be able to display the function that called it. ... One involved using C macros. ... > said that the code for an inline function gets replaced wherever the ... _preprocessing_ time. ...
    (comp.lang.cpp)
  • Re: files "." and ".." from readdir()
    ... What is your justification for others to use an inline function over a ... | There is no alloca in the macro above. ... suggested to use inline functions instead of macros. ... not called from in the same compiled unit. ...
    (comp.unix.programmer)
  • Re: What is the gain of "inline"
    ...  For example, the following inline function ... )> without evaluating its argument more than once: ... which is about comparing macros with inline functions. ... For me, if a function isn't a performance hazard, it stays as a ...
    (comp.lang.c)
  • Re: inline vs macro
    ... thing written as an inline function. ... Using macros is lazy and stupid. ... Upgrade your compiler. ... Use function macros and hope for the best. ...
    (comp.lang.c)
  • Re: Is there stack associated when a executing an inline function?
    ... inline function execution or do they execute just like macros? ... useful for compilers that don't. ... macros just perform text substitutions, ...
    (comp.lang.c)