Re: Is there stack associated when a executing an inline function?
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 15:06:27 +0530
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.
.
- Follow-Ups:
- Re: Is there stack associated when a executing an inline function?
- From: Richard Tobin
- Re: Is there stack associated when a executing an inline function?
- References:
- Prev by Date: Re: Why atexit is limited to 32 functions?
- Next by Date: Re: Is there stack associated when a executing an inline function?
- Previous by thread: Re: Is there stack associated when a executing an inline function?
- Next by thread: Re: Is there stack associated when a executing an inline function?
- Index(es):
Relevant Pages
|