functions in stack?

This is a discussion on functions in stack? within the C Programming forums, part of the General Programming Boards category; I have no ideas about the details of the functions in the main function layout in memory ,i only know ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    wuhan ,hubei ,china
    Posts
    7

    functions in stack?

    I have no ideas about the details of the functions in the main function layout in memory ,i only know tha t they are in the temp stack and I want to know some thing detail,please?
    for instance:
    #include <stdio.h>
    int foo()
    { int array[3];
    int i;
    for(i=0;i<=3;i++)
    array[i]-=3;
    return 1;
    }
    int main()
    {
    foo();

    return 0;
    }
    of course ,we know that the i have exceed the boundary of the array,and it sometime pointer to the call of the function foo(),so please explain the details ?
    Last edited by kiss; 12-14-2009 at 11:44 PM.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Nothing to do with C specifically, everything to do with your implementation.

    What details are you after exactly? How the local scope variables in foo() are added/used on the stack? How the call stack looks after and before calling foo()?

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    http://cboard.cprogramming.com/dos-p...ead-first.html
    There is no "standard" way to know if you've written outside the array in C. It can be done, but it's not trivial.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by kiss View Post
    I have no ideas about the details of the functions in the main function layout in memory ,i only know tha t they are in the temp stack and I want to know some thing detail,please?
    for instance:
    of course ,we know that the i have exceed the boundary of the array,and it sometime pointer to the call of the function foo(),so please explain the details ?
    Function calling explained
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack Implementation and Exceptions
    By audinue in forum C Programming
    Replies: 4
    Last Post: 06-22-2008, 09:32 AM
  2. Stack overflow errors in 3 areas
    By ulillillia in forum C Programming
    Replies: 13
    Last Post: 04-29-2007, 03:20 PM
  3. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  4. Help With Stacks
    By penance in forum C Programming
    Replies: 7
    Last Post: 10-09-2005, 02:47 PM
  5. Functions, stack
    By Ariod in forum C Programming
    Replies: 9
    Last Post: 07-28-2005, 03:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21