473,411 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Is there stack associated when a executing an inline function?

Hi,
I need to know if stack frames are generated in case of a
inline function execution or
do they execute just like macros?
if they execute like macros, then what is the need for having
inline function?
where would you use macros and where inlines?

Thanks
Mahesh
Feb 29 '08 #1
15 2607
In article <fq**********@registered.motzarella.org>,
santosh <sa*********@gmail.comwrote:
> 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.
You generally don't lose type checking with macros, because the
expansion gets type checked in the usual way. If getc is a macro and
you call it with something that isn't a FILE *, you'll probably
get a bunch of fatal, if unclear, errors.

The more compelling reason for inline functions is that you can't
use arbitrary constructs in macros that are used in expressions.
C's macros are just powerful enough to let you write getc and putc,
but anything that needs declarations or a loop can't be done.

-- Richard
--
:wq
Feb 29 '08 #2
In article <1f**********************************@u10g2000prn. googlegroups.com>,
Mahesh <ma********@gmail.comwrote:
>Hi,
I need to know if stack frames are generated in case of a
inline function execution or
do they execute just like macros?
if they execute like macros, then what is the need for having
inline function?
where would you use macros and where inlines?

Thanks
Mahesh
Be aware that use of the word "stack" in this ng (even if the subject is
pancakes), by non-Clique members, will result in flamage.

Feb 29 '08 #3
Kenny McCormack wrote:
Be aware that use of the word "stack" in this ng (even if the subject is
pancakes), by non-Clique members, will result in flamage.
Good point - many newbies are unaware that not all machine
architectures include a stack mechanism.

Flames are generally reserved for intellectually conceited types
who present ignorance as virtue.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Feb 29 '08 #4
In article <47***************@iedu.com>,
Morris Dovey <mr*****@iedu.comwrote:
>Kenny McCormack wrote:
>Be aware that use of the word "stack" in this ng (even if the subject is
pancakes), by non-Clique members, will result in flamage.

Good point - many newbies are unaware that not all machine
architectures include a stack mechanism.
Wow! Can you say 'goosestepping' ?
>Flames are generally reserved for intellectually conceited types
who present ignorance as virtue.
More goosestepping.

Feb 29 '08 #5
jacob navia <ja***@nospam.comwrites:
Mahesh wrote:
> I need to know if stack frames are generated in case of a
inline function execution or
do they execute just like macros?

A stack <framewill not be generated but any local
storage that the inline function uses will be added to
the local storage of the calling function.
How do you know? Can you cite the standard to support this claim?

The implementation you describe is certainly plausible, but the
standard says nothing about stack frames, either for inline functions
or for ordinary functions. See C99 6.7.4. To the original poster: a
recent draft of the C99 standard can be downloaded in PDF format from
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>.

Briefly, the standard imposes some restrictions on inline functions,
but otherwise says only that they behave like ordinary functions.

[snip]

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 29 '08 #6
Kaz Kylheku wrote:
In principle, blocks can allocate and deallocate individually. That
requires a small overhead, but it would be a smart implementation
strategy for blocks that contain large arrays. Or at least a code-
generation option, if not default behavior.
Care to name a SINGLE compiler system that does this kind of stuff?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #7
On Feb 29, 11:08*am, jacob navia <ja...@nospam.comwrote:
It would be completely weird that in an inline procedure the compiler
would save the current stack pointer and establish a new stack
frame since there is no function call.
However, it wouldn't be weird at all if the inlined procedure simply
moves the stack pointer by some delta to enlarge the current frame,
then references all of its locals with respect to the current frame,
and then moves the stack pointer back by the same delta upon
termination to release the storage.
Feb 29 '08 #8
Kaz Kylheku wrote:
On Feb 29, 11:08 am, jacob navia <ja...@nospam.comwrote:
>It would be completely weird that in an inline procedure the compiler
would save the current stack pointer and establish a new stack
frame since there is no function call.

However, it wouldn't be weird at all if the inlined procedure simply
moves the stack pointer by some delta to enlarge the current frame,
then references all of its locals with respect to the current frame,
and then moves the stack pointer back by the same delta upon
termination to release the storage.
That is normal, but that is not a stack frame!

That is just increasing the stack, like when you use
alloca().

That function (alloca()) doesn't create a stack frame.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #9
In article <12**********************************@59g2000hsb.g ooglegroups.com>,
Kaz Kylheku <kk******@gmail.comwrote:
>However, it wouldn't be weird at all if the inlined procedure simply
moves the stack pointer by some delta to enlarge the current frame,
then references all of its locals with respect to the current frame,
and then moves the stack pointer back by the same delta upon
termination to release the storage.
But what would be the point?

-- Richard
--
:wq
Feb 29 '08 #10
Richard Tobin wrote:
>
In article <12**********************************@59g2000hsb.g ooglegroups.com>,
Kaz Kylheku <kk******@gmail.comwrote:
However, it wouldn't be weird at all if the inlined procedure simply
moves the stack pointer by some delta to enlarge the current frame,
then references all of its locals with respect to the current frame,
and then moves the stack pointer back by the same delta upon
termination to release the storage.

But what would be the point?
It'd allow re-use of that memory by another (subsequent) inlined
procedure or function call. Waste not, want not.

--
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/Projects/Monitor/
Feb 29 '08 #11
In article <47***************@iedu.com>,
Morris Dovey <mr*****@iedu.comwrote:
>However, it wouldn't be weird at all if the inlined procedure simply
moves the stack pointer by some delta to enlarge the current frame,
then references all of its locals with respect to the current frame,
and then moves the stack pointer back by the same delta upon
termination to release the storage.
>But what would be the point?
>It'd allow re-use of that memory by another (subsequent) inlined
procedure or function call. Waste not, want not.
Multiple inlined functions can use the same stack space without
adjusting the stack pointer. It's not significantly different from:

void foo(int a)
{
...
{
int b;
...
}
...
{
double c;
...
}
...
}

But actually I'd misread the article; it is indeed quite reasonable to
adjust the stack pointer during the execution of a function, and it
can be done even when there are no inline function calls or nested
blocks, at the end of some variable's useful life. I don't know if
any C implementations do that, but some implementations of other
languages do.

-- Richard

--
:wq
Feb 29 '08 #12
jacob navia wrote:
Kaz Kylheku wrote:
>In principle, blocks can allocate and deallocate individually. That
requires a small overhead, but it would be a smart implementation
strategy for blocks that contain large arrays. Or at least a code-
generation option, if not default behavior.

Care to name a SINGLE compiler system that does this kind of stuff?
Most. They allocate a stack block for their local storage, and
then let the push/pop mechanism handle the temporaries during
expression evaluation, for example. That is why extending local
storage (from an inline function) requires special care and timing.

Other things that can grow on top of allocated stack storage are
saves and returns to handle interrupts.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 29 '08 #13
CBFalconer wrote:
jacob navia wrote:
>Kaz Kylheku wrote:
>>In principle, blocks can allocate and deallocate individually. That
requires a small overhead, but it would be a smart implementation
strategy for blocks that contain large arrays. Or at least a code-
generation option, if not default behavior.
Care to name a SINGLE compiler system that does this kind of stuff?

Most. They allocate a stack block for their local storage, and
then let the push/pop mechanism handle the temporaries during
expression evaluation, for example.

Yes. But I was asking for the hypothetical compiler that
Mr Kylheku proposed, that allocates not from the stack but from
the heap.

I know that most compilers allocate from the stack, thats what I was
saying.

That is why extending local
storage (from an inline function) requires special care and timing.
Correct, that is why I said that in my first message to this thread.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Feb 29 '08 #14
On Feb 29, 2:20*pm, CBFalconer <cbfalco...@yahoo.comwrote:
jacob navia wrote:
Kaz Kylheku wrote:
In principle, blocks can allocate and deallocate individually. That
requires a small overhead, but it would be a smart implementation
strategy for blocks that contain large arrays. Or at least a code-
generation option, if not default behavior.
Care to name a SINGLE compiler system that does this kind of stuff?

Most. *They allocate a stack block for their local storage, and
then let the push/pop mechanism handle the temporaries during
expression evaluation, for example. *That is why extending local
storage (from an inline function) requires special care and timing.
You'd never pop a temporary within the inlined block that was pushed
outside of it. Everything just has to be properly nested. That would
be the extent of the special care and timing.
Mar 1 '08 #15
On Feb 29, 3:37*pm, jacob navia <ja...@nospam.comwrote:
CBFalconer wrote:
jacob navia wrote:
Kaz Kylheku wrote:
>In principle, blocks can allocate and deallocate individually. That
requires a small overhead, but it would be a smart implementation
strategy for blocks that contain large arrays. Or at least a code-
generation option, if not default behavior.
Care to name a SINGLE compiler system that does this kind of stuff?
Most. *They allocate a stack block for their local storage, and
then let the push/pop mechanism handle the temporaries during
expression evaluation, for example.

Yes. But I was asking for the hypothetical compiler that
Mr Kylheku proposed, that allocates not from the stack but from
the heap.
But I didn't write anything about any heap. I'm only writing about
stack allocation: moving the stack pointer to obtain extra automatic
storage for a block, which is then released when the block terminates.
That ``small overhead'' I'm referring to is moving the stack pointer
back and forth.
Mar 1 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax...
5
by: ip4ram | last post by:
I am quite puzzled by the stack overflow which I am encountering.Here is the pseudocode //define stack structure //function operating on stack void my_stack_function( function parameters) {...
25
by: Brian Lindahl | last post by:
I'm using a temporary buffer to transfer some data and would rather not allocate it on the heap. The problem is that the size of the buffer is only known upon entry into the function that utilizes...
13
by: Kenneth Lantrip | last post by:
In Ansi-C C99 or Standard C or in GCC... Is there a way to push a value onto the stack and then later retrieve it within the same function? void foo(void) {
26
by: bahadir.balban | last post by:
Hi, When you define varibles in the middle of your function call (C99), such as: if(i == 5) { int x = 5; int z = 2; }
9
by: shine | last post by:
what is the difference between a heap and a stack?
7
by: Dougan | last post by:
I've seen code that allocates an object on the stack and then saves a class reference to it. example: void ScribbleArea::resizeImage( const QSize &newSize) { QImage newImage( newSize, );...
5
by: Joel | last post by:
I would like to learn if there is any difference between the stack that MSIL uses for each method for executing instructions and the stack that it uses for storing Value types. Are they the same?...
10
by: kid joe | last post by:
Hi all, I'm using a temporary buffer to transfer some data and would rather not allocate it on the heap. The problem is that the size of the buffer is only known upon entry into the function...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.