Compiler Differences (under Linux)

S

sternr

Hi,

In C\C++, method invocation is translated to the following behaviour:
1. push the method arguments to the stack
2. move the program counter to the method's instrunctions address
3. the new method will always start with the following instruction set:
push %ebp
move %esp, %ebp
push %edi
push %esi
pusb %ebx

4. and will end with the reverse code (pop).

My question is: are there any differences in this behaviour between different C compilers (under linux)?
If so, could you give an example?

Thanks!

--sternr
 
E

Eric Sosman

Hi,

In C\C++, method invocation is translated to the following behaviour:
1. push the method arguments to the stack

Maybe. Some systems pass arguments in registers, or in a mix
of registers and memory locations, or in stranger ways.
2. move the program counter to the method's instrunctions address

Maybe. At least one system uses a special instruction that
points to a location a few bytes *before* the first instruction of
the called function.
3. the new method will always start with the following instruction set:
push %ebp
move %esp, %ebp
push %edi
push %esi
pusb %ebx

Not on an IBM zSeries or a Sun SPARC or ...
4. and will end with the reverse code (pop).

Again, you're making a lot of unwarranted assumptions about the
architecture and instruction set of the platform on which you run C.
On some systems the called function cleans up the stack (or whatever
mechanism is used for arguments and local storage), while on other
systems it's the caller's responsibility, and on still others it's a
shared task.
My question is: are there any differences in this behaviour between different C compilers (under linux)?
If so, could you give an example?

What this all boils down to is that you've asked your question in
the wrong newsgroup. You're not asking about C -- which runs on many
systems with many varying ways of doing things -- but about Linux, and
apparently about Linux on a specific kind of hardware. You should try
a Linux forum, not a language forum. Good luck!
 
A

Anders Wegge Keller

sternr said:
My question is: are there any differences in this behaviour between
different C compilers (under linux)? If so, could you give an
example?

The calling convention is part of the ABI for the particular
architecture. So it's probably not that topical here. Wikipedia lists
different CC's here: http://en.wikipedia.org/wiki/Calling_convention

There you will find that the conventions is largely a product of how
many registers are available. Your example would have been different
on linux-pppc, for instance.
 
K

Kenny McCormack

Hi,

In C\C++, method invocation is translated to the following behaviour:

I can hardly wait to hear what the regs have to say about your "C\C++".

That must be the DOS/Windows specific version of the mythical,
non-existent language that is so often mentioned around here.

--
One of the best lines I've heard lately:

Obama could cure cancer tomorrow, and the Republicans would be
complaining that he had ruined the pharmaceutical business.

(Heard on Stephanie Miller = but the sad thing is that there is an awful lot
of direct truth in it. We've constructed an economy in which eliminating
cancer would be a horrible disaster. There are many other such examples.)
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top