Compiler Differences (under Linux)

Discussion in 'C Programming' started by sternr, Feb 20, 2011.

  1. sternr

    sternr Guest

    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
    sternr, Feb 20, 2011
    #1
    1. Advertising

  2. sternr

    Eric Sosman Guest

    On 2/20/2011 9:51 AM, sternr wrote:
    > 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!

    --
    Eric Sosman
    lid
    Eric Sosman, Feb 20, 2011
    #2
    1. Advertising

  3. sternr <> writes:

    > 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.


    --
    /Wegge

    Leder efter redundant peering af dk.*,linux.debian.*
    Anders Wegge Keller, Feb 20, 2011
    #3
  4. In article <>,
    sternr <> wrote:
    >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.)
    Kenny McCormack, Feb 20, 2011
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hshdude
    Replies:
    12
    Views:
    1,041
    Dimitri Maziuk
    Nov 4, 2004
  2. bronby
    Replies:
    1
    Views:
    592
    Andrew Thompson
    Jul 15, 2005
  3. Home_Job_opportunity
    Replies:
    0
    Views:
    485
    Home_Job_opportunity
    Jan 8, 2009
  4. Home_Job_opportunity
    Replies:
    0
    Views:
    569
    Home_Job_opportunity
    Jan 14, 2009
  5. Merciadri Luca
    Replies:
    5
    Views:
    1,069
    Merciadri Luca
    Oct 14, 2010
Loading...

Share This Page