Thread: What happens behind the scene when value is returned ?

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    11

    What happens behind the scene when value is returned ?

    Dear everybody ..

    I'm wondering what happens behind the scene when a function encounters return statement, and hence it starts to pass the value to the caller routine .. how does this process happen in details ?? Steps approach is very recommended to meet my understanding methodology

    Thanks everybody for help in advance

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,656
    Quote Originally Posted by afesheir View Post
    what happens behind the scene ...
    010111010110100000110111000101110101
    010101011000000010111111111111100001
    010111010110100110111000101110101010
    010111010110100000110111000101110101
    010111010110100000110000101110101010


    Seriously..STFW
    C Function Call Conventions, UMBC CMSC 313, Spring 2002

    btw.. Welcome
    (I'm sure Adak will post his signature welcome message soon ! )
    Last edited by manasij7479; 11-30-2011 at 02:17 PM.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    sorry Sir ?

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,656
    Quote Originally Posted by afesheir View Post
    sorry Sir ?
    Did you follow the above link (or do a Web Search) ?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by afesheir View Post
    Dear everybody ..

    I'm wondering what happens behind the scene when a function encounters return statement, and hence it starts to pass the value to the caller routine .. how does this process happen in details ?? Steps approach is very recommended to meet my understanding methodology

    Thanks everybody for help in advance
    Read the link Manasij provided for you...

    In a nutshell...

    The return value is placed in a CPU register
    Local variables are destroyed
    The program's stack is restored to it's "condition on entry"
    The return address is taken from the stack
    and, finally, the CPU jumps to the return address.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    11
    Thanks guys .. this was very helpful ..

    It's a pleasure to add the following:

    x86 - What is stack frame in assembly? - Stack Overflow
    Stack Frame

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Keep in mind that just because there's one way to do it doesn't mean that there aren't other ways depending on the CPU, OS, or compiler you're using. And the details will also differ if you return, for example, a large structure. And optimizations can combine, reorder or eliminate various steps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Blender scene graph?
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 04-22-2010, 11:34 PM
  2. Scene Graph, Quadtree, Octtree, and Scene Manager.
    By sarah22 in forum Game Programming
    Replies: 1
    Last Post: 04-17-2010, 09:20 AM
  3. Scene Description Language in C
    By shameerkm in forum C Programming
    Replies: 1
    Last Post: 01-12-2010, 01:16 AM
  4. Scene graphs
    By VirtualAce in forum Game Programming
    Replies: 1
    Last Post: 08-09-2009, 12:40 PM
  5. Scene Graph - Compiling
    By Shamino in forum Game Programming
    Replies: 17
    Last Post: 03-05-2006, 11:57 AM