cleaning stack after a fn call 
Author Message
 cleaning stack after a fn call

Hi all,

        please, could anyone tell me, who is cleaning the stack after a
function call?

        Is it a caller or the function, that is called? (and in Pascal?)

                                        Thanks, Jan.

PLEASE, could you cc to my personal e-mail address? Thank you.
--
------------------------------------------------------------------------

------------------------------------------------------------------------



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call



Quote:
>Hi all,

>    please, could anyone tell me, who is cleaning the stack after a
>function call?

>    Is it a caller or the function, that is called? (and in Pascal?)

This isn't a feature of the C or Pascal language, but of the language
implementation. A language implementation has to do whatever it takes
to set the semantics of the program into motion.

You can't write a C or Pascal program to detect how linkage between
functions is being accomplished, so it isn't required to work in any
particular way. There doesn't even have to be a stack.

Does it matter where the discarding of automatic storage takes place, as long
as your functions are getting their arguments and returning values properlY?
Because it does not matter, different implementations of the same language
tend to do it differently.



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call


Quote:
> Hi all,
>    please, could anyone tell me, who is cleaning the stack after a
> function call?
>    Is it a caller or the function, that is called? (and in Pascal?)
>                                    Thanks, Jan.
> PLEASE, could you cc to my personal e-mail address? Thank you.
> ------------------------------------------------------------------------

> ------------------------------------------------------------------------

In C(++) - the caller cleans, Pascal - the called cleans;
there are exceptions of course, and it depends on the
vendor.

--
##################################
#Blue Skies!                     #

#remove "no-spam-" when replying.#
##################################



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call



Quote:
>In C(++) - the caller cleans, Pascal - the called cleans;

Can you show me a code snippet of C++ or Pascal which illustrates
that ``caller cleans''?


Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call

Quote:

> Hi all,

>         please, could anyone tell me, who is cleaning the stack after a
> function call?

>         Is it a caller or the function, that is called? (and in Pascal?)

Your question implies that a stack is actually used.  While most of the
time it IS used, there exist machines that don't have stacks (per se).
That being said, machines that DO use a stack for arguments TYPICALLY
clean up the stack (or its equivalent) in the callING function.  This can
be shown with the use of varadic functions (printf) with more arguments
than needed.  If the callED function did the cleanup, it would need to
know the number of arguments to clean up (which isn't passed in most
machine/compiler combinations).

Pascal (again TYPICALLY) has the cleanup in the callED function.  This
means that the routine being called needs to know how many arguments are
being passed to it, so Pascal has little (if any) support for varadic
function calls.

All of this changes if the compiler decides to change how it does things.
Since this is unspecified in the language/standard, it can do as it
pleases, and all of the above assumptions will be WRONG.  Most of the time
it isn't that way.

p.s.  Why does this make any difference.  If you want to know, ask the
compiler to divulge its generated machine code.  Most have an option that
DOES just this.

--




Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call

Quote:

>    please, could anyone tell me, who is cleaning the stack after a
> function call?

You don't need to know that.

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call




:>In C(++) - the caller cleans, Pascal - the called cleans;

: Can you show me a code snippet of C++ or Pascal which illustrates
: that ``caller cleans''?

Visual C++ uses both ways, depending on the context.  You can find
out very quickly how your compiler does it by setting its
assembly code listing option flag (if it has one).

-- Wetboy



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call


Quote:


> >In C(++) - the caller cleans, Pascal - the called cleans;

> Can you show me a code snippet of C++ or Pascal which illustrates
> that ``caller cleans''?

I'm not sure that I'm gonna spend the time to
prove this. Just use YOUR compiler to produce
an assembly output file and examine it yourself.

This is why "C" applications compiled with the
pascal switch on (pascal calling convention) are
smaller (faster?). In the old days, when space/memory
was an issue, this is a "trick" we used to do.

--
##################################
#Blue Skies!                     #

#remove "no-spam-" when replying.#
##################################



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call

Quote:
>please, could anyone tell me, who is cleaning the stack after a
>function call?

This is usually entirely up to you. Most environments support compiler
switches or keywords that let you specify which calling convention is
used. The way functions are called is transparent to the language
itself, unless you are trying to co-exist with an OS's API or another
language. That's the only time it becomes a factor.

Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call

Quote:


>> Hi all,
>> please, could anyone tell me, who is cleaning the stack after a
>> function call?
>> Is it a caller or the function, that is called? (and in Pascal?)
>> Thanks, Jan.
>> PLEASE, could you cc to my personal e-mail address? Thank you.
>> ------------------------------------------------------------------------

>> ------------------------------------------------------------------------

>In C(++) - the caller cleans, Pascal - the called cleans;
>there are exceptions of course, and it depends on the
>vendor.

I have a C++ compiler that lets me specify the calling convention.  Must be
broken.
But it always leaves my programs lemony-fresh.
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.infoseek.com


Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call

Quote:




>:>In C(++) - the caller cleans, Pascal - the called cleans;

>: Can you show me a code snippet of C++ or Pascal which illustrates
>: that ``caller cleans''?

>Visual C++ uses both ways, depending on the context.  You can find
>out very quickly how your compiler does it by setting its
>assembly code listing option flag (if it has one).

Can you show me a C++ program which displays its own assembly code
listing?


Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call



Quote:



>> >In C(++) - the caller cleans, Pascal - the called cleans;

>> Can you show me a code snippet of C++ or Pascal which illustrates
>> that ``caller cleans''?

>I'm not sure that I'm gonna spend the time to
>prove this. Just use YOUR compiler to produce
>an assembly output file and examine it yourself.

I did. Caller didn't clean. Is my C++ compiler defective?

Quote:
>This is why "C" applications compiled with the
>pascal switch on (pascal calling convention) are
>smaller (faster?). In the old days, when space/memory
>was an issue, this is a "trick" we used to do.

Actually the caller-cleans can be faster because arguments can be reused, and
also you can clean up several function calls in one operation, thus amortizing
some of the cost.

But what does this have to do with C++ or Pascal? There is no such thing
as ``Pascal'' calling conventions or C calling conventions. Neither of
these languages define such conventions.



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call


Quote:


>>In C(++) - the caller cleans, Pascal - the called cleans;
>>there are exceptions of course, and it depends on the
>>vendor.

>I have a C++ compiler that lets me specify the calling convention.  Must be
>broken.
>But it always leaves my programs lemony-fresh.

Is it kid tested and mother approved?


Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call


[snip]

Quote:
> I did. Caller didn't clean. Is my C++ compiler defective?

No, not defective. As I said, it may depend on the
vendor. They may even be passing parms in registers,
which is another way of doing things.

Quote:
> Actually the caller-cleans can be faster because arguments can be reused, and
> also you can clean up several function calls in one operation, thus amortizing
> some of the cost.

This is incorrect. If it's caller cleans, then EVERYWHERE there is a
function call, there is parameter set up, the call, then clean up.
This'll be for every function call. If you have a particular function
that is being called from 100 different locations in your source files,
then you'll have 100 setups, calls, then clean ups.

If it's called-cleans, then the function being called cleans up after
itself IN JUST ONE PLACE.  It's easy realize the difference; you should,
although, use a "significant" size application to see the dramatic
decrease in size, speed.  You might not see anything with a "hello world"
application.

Quote:
> But what does this have to do with C++ or Pascal? There is no such thing
> as ``Pascal'' calling conventions or C calling conventions. Neither of
> these languages define such conventions.

Actually, you're incorrect here again.  Ask any developer that has been
involved in this respect; going back, say 10 years. This was a
commonplace thing to do.  There IS a Pascal calling convention and there
IS a "C" calling convention ("C" compilers will discuss this subject
matter in great detail). This is because Pascal sets up, calls, and
cleans up in a different manner than "C" does.  This is why "C" can offer
variable length argment lists.

The "other" convention is known as the "register" calling convention.
This is where the arguments, where applicable, are passed in registers.
Watcom was (if I remember correctly) the first to introduce this. Alot of
compilers these days use this style because it's faster and cheaper.

I dont have the K&R book here with me, but I think I remember them
discussing the "C" convention.

--
##################################
#Blue Skies!                     #

#remove "no-spam-" when replying.#
##################################



Tue, 05 Sep 2000 03:00:00 GMT  
 cleaning stack after a fn call






:>:>In C(++) - the caller cleans, Pascal - the called cleans;
:>
:>: Can you show me a code snippet of C++ or Pascal which illustrates
:>: that ``caller cleans''?
:>
:>Visual C++ uses both ways, depending on the context.  You can find
:>out very quickly how your compiler does it by setting its
:>assembly code listing option flag (if it has one).

: Can you show me a C++ program which displays its own assembly code
: listing?

Yes, I could.  But, given the similar response you made to
another poster in this thread, I think maybe it's time
for you to make a little effort on your own.

-- Wetboy



Tue, 05 Sep 2000 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. varargs fn calling varargs fn?

2. Base::fn(int) is covered by Derived::fn()

3. fn(array) vs. fn(&array)

4. diffrence between fn and member fn

5. (void) casts on fn() calls

6. Calling base virtual fn through pointer

7. TextOut keeps old data between multiple fn calls

8. varargs fn calling va

9. destructor is called before copy-constructor on temporary class (allocated on stack during function call)

10. Atl NT service calling VB ActiveX dll had problem when clean-up

11. Showing Call Stack and Determine which object is not valid LARGE CHUNK OF CODE

12. Call Stack not showing up?

 

 
Powered by phpBB® Forum Software