clean up of stack

J

Jeff Kish

Greetings.

I know that some languages/compilers cause functions to clean up the stack by
the caller and some by the callee. Is this a language dependent quality or is
it not specified by the language and hence possibly different between two c++
compilers, say borland and ms?

thanks
Jeff Kish
 
V

Victor Bazarov

Jeff said:
I know that some languages/compilers cause functions to clean up the
stack by the caller and some by the callee. Is this a language
dependent quality or is it not specified by the language and hence
possibly different between two c++ compilers, say borland and ms?

The Standard does not specify that, nor does it actually specify how
function calls are implemented. For all Standard cares, there can be
no stack whatsoever, and nothing to "clean up".

V
 
O

osmium

Jeff Kish said:
I know that some languages/compilers cause functions to clean up the stack
by
the caller and some by the callee. Is this a language dependent quality or
is
it not specified by the language and hence possibly different between two
c++
compilers, say borland and ms?

The biggy here is a function of the *language* and whether it supports
arguments that vary in number, as printf( )does in C. Pascal OTOH has no
siimilar such creature. The callee cleans up a Pascal stack and the caller
cleans up the C stack. Of course, if there is no stack, as some kind soul
has carefully pointed out, no one cleans up the non-existent stack.
 
J

James Kanze

It could be different between two C++ compilers. It could be
different between extern "C" and extern "C++" functions, or
between varargs function and non varargs functions, or between
member functions and non-member functions.
The biggy here is a function of the *language* and whether it
supports arguments that vary in number, as printf( )does in C.

Not at all. An implementation can pretty much do what it wants
here. The C standards committee took away the right to call
printf without a prototype in view, way back in 1989,
expressedly so that a C compiler did not have to support varargs
unless the function was explicitly declared to do so, and of
course, C++ has never had that right. On Intel architecture,
I've found three different variants for C/C++:
-- callee cleans up, except for varargs, in both languages,
-- callee cleans up in C++, caller in C, and
-- caller cleans up everywhere.
Pascal OTOH has no siimilar such creature. The callee cleans
up a Pascal stack and the caller cleans up the C stack.

I've seem Pascal compilers for Intel which used the normal C
conventions as well.

Of course, on a modern machine, the compiler will probably pass
non-class arguments in registers, and not on the stack anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,540
Members
48,275
Latest member
tetedenuit01

Latest Threads

Top