Thread: stack overflow

  1. #1
    Unregistered
    Guest

    stack overflow

    My program is experiencing a stack overflow problem. I have checked all my arrays for possible overflow and they seem ok. All function calls seem ok...not done recursively. What else could cause this problem? I would have pasted the code here, however it's approx 2300 lines. The development environment is MS Dev C++ (the code is C). I have found a way to overcome this problem and that is to set the stack size to an ungodly size in MS DEV....this is a kludge I know. Please offer advice!
    Thanks in advance! Prince

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do you have any local arrays which look like

    int big[1000][1000];

  3. #3
    Unregistered
    Guest
    No. All arrays are global. I don't use any local's at all. I did this by choice to avoid the potential of smashing the stack. Also, I don't have any functions that call themselves. I'm a little bewildered to say the least.

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    are you sure you don't indirectly make recursive calls? functions calling eachother? That sounds like the most likely unless you had some wacky memory overwrite

  5. #5
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Just use gdb. You should be able to tell if the stack is corrupted or your calling functions recursivly.

  6. #6
    Unregistered
    Guest
    My mistake. They do call each other. What should I do to correct this problem?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What should I do to correct this problem?
    Make sure that there's a limiting condition where they stop calling each other. Or redesign your program so that it is structured better.

    -Prelude
    My best code is written with the delete key.

  8. #8
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I vote for redesign. I can't imagine an algorithm where you absolutely need to do that. There are other ways I'm sure.

  9. #9
    Unregistered
    Guest
    Since my program is too large to paste I basically came up with the function call order...it's very generic. Can you look at it to see what the problem is? One note: Although there are numerous function calls, no function calls itself nor does for example function A call function B and then function B calls function A. Here is the generis call structure:

    int main()
    {
    Function_A() ;
    }

    void Function_A(void)
    {
    Function_B() ;
    }

    void Function_B(void)
    {
    Function_C() ;
    }

    void Function_D(void)
    {
    Function_A() ;
    -or-
    Function_E() ;
    }

    void Function_E(void)
    {
    Function_C() ;
    }

    void Function_C(void)
    {

    Function_F() ;
    -or-
    Function_G() ;
    -or-
    Function_H() ;
    -or-
    Function_D() ;

    }

    void Function_F(void)
    {

    Function_I() ;
    }

    void Function_G(void)
    {
    Function_I() ;
    }

    void Function_H(void)
    {
    Function_I() ;
    }

    void Function_I(void)
    {
    Function_D() ;
    -or-
    Function_J() ;
    }

    void Function_J(void)
    {
    Function_L() ;
    -or-
    Function_K() ;
    }

    void Function_K(void)
    {
    Function_D() ;
    -or-
    Function_L() ;
    }

    void Function_L(void)
    {
    Function_D() ;
    }

    I sincerely appreciate all of the input so far!

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    woah. that's wierd.

    It's pretty hard to come up with a new architecture suggestions for you when you haven't posted any real code. Isn't there a way of attaching a file to this board or something? Yes, there it is right below where I'm typing. Use that

  11. #11
    Unregistered
    Guest
    Fill or anyone else,

    Does the call structure look as though it's recursive or not? I don't think it does. You shouldn't need the code if this is a duplicate (albeit very generic) of the exact call structure used in the code.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Does the call structure look as though it's recursive or not?
    Yes, it looks pretty nasty too. I highly recommend that you redesign so that it's not quite so twisty. If you can look at the call structure and have trouble following the flow then there's something wrong.

    -Prelude
    My best code is written with the delete key.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    C which calls D which can call E which calls C, is recursion.

    If any of the functions[function calls], pushed onto the stack after you are initially called, can call you, then you have recursion.

    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Unregistered
    Guest
    Thanks Quzah! Now what can I do to fix it?

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Unregistered
    Thanks Quzah! Now what can I do to fix it?
    This has already been answered. Redesign your program.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack overflow errors in 3 areas
    By ulillillia in forum C Programming
    Replies: 13
    Last Post: 04-29-2007, 03:20 PM
  2. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM