stack overflow?

This is a discussion on stack overflow? within the C++ Programming forums, part of the General Programming Boards category; I have a function with 55 arguments. I don't think anything is wrong with the syntax, there are no compile ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    stack overflow?

    I have a function with 55 arguments. I don't think anything is wrong with the syntax, there are no compile errors, but when the program starts i get the windows has encountered an error crap and my program closes. i go to debug and it says somehting like stack overflow. is there a limit to how many arguments?

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    can i try and help post your code

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I have a function with 55 arguments. I don't think anything is wrong with the syntax, there are no compile errors, but when the program starts i get the windows has encountered an error crap and my program closes. i go to debug and it says somehting like stack overflow. is there a limit to how many arguments?
    55? Is it just me or is that way too many arguments for one function? I think you should try grouping some of the parameters into a struct, or splitting the function up into smaller, more specialized functions.

    http://www.google.com/search?q=stack+overflow

  4. #4
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    all of the variables im passing are of the same type, which is from a struct. so i couldnt put them all into one struct

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Way too many arguments
    The amount of stack space depends on
    - Your OS
    - Your compiler
    - Your compiler options
    - probably some other stuff as well.


    If you're trying to pass all the members of a structure like
    func( foo.a, foo.b );

    Consider for brevity of typing
    func ( foo );

    And to save lots of space
    func ( &foo ); // pointer to foo

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Where is the Code

    Can We See the Code Please...

    If not ... You should read something about the Memory mangments .... I think that you have an idea about RAM and stacks... Please chick your code again ...
    if you have a loop that creat alot of variables and funtions... that will give you stack over flow ....

    write your code and we will chick that outtt....
    C++
    The best

  7. #7
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    first of all, that is a reference to foo, not a pointer to foo. second of all, i know that! let me explain:

    here is what my code is like:
    Code:
    struct ROOM
    {
        ROOM* north;
        ROOM* west;
        ROOM* east;
        ROOM* south;
        //...etc
    };
    
    //now i declare 55 variables of type ROOM:
    ROOM room1;
    ROOM room2;
    ROOM room3;
    ROOM room4;
    //....etc until room55
    
    //now this is how i pass the variables:
    void func(ROOM& room1, ROOM& room2, ROOM& room3)//...til 55
    are you saying that i can pass all the variables of type room by doing something like passing ROOM when called in main, and use &ROOM for the prototype and definition? so....:
    Code:
    void func(&ROOM); //prototype
    
    //in main
    func(ROOM);
    
    //definition
    void func(&ROOM)
    {
        //blah blah, being able to use all 55 of my 'ROOM's?
    }
    is that possible?

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    //....etc until room55

    Perhaps an array then
    ROOM rooms[55];

    Then
    void func ( ROOM rooms[] );


    Which would be called
    func ( rooms );

  9. #9
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    ...ok that last option i said above is not possible....

    i only use the function for more organization, i set all the attributes for each 'ROOM' in the function, thats all. i COULD do it all outside a fuction, it would be THAT much of a sacrifice, but do you guys get the situation now?

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Chick your code again ...

    I don't think that you have a problem....

    IT always happend ...
    Just chick youtr code again,,,,
    Not on the computer ...
    Print your code out ... and look at it on paper......
    and compile it on paper ....

    I got this prblem before...
    C++
    The best

  11. #11
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    I say go with the Array of Rooms.

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Can you pass class by refrence

    I don't know if this is the error or not ....

    Code:
     void func(&ROOM); // I don't think that is a good sug.
    cout<< " I would rather go with arrays";
    C++
    The best

  13. #13
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    since you already pass by reference, so far so good........

    you must know that if you "pass" something to a function even by reference it is still put on the stack, althought in case of "reference" the only thing that is put on the stack is a pointer..

    here's a suggestion: use a POINTER POINTER to a struct......

    no it is not a typo error --- it's a double pointer......you can pass a pointer to all the existing pointers, which makes the stack a lot smaller....

    you can accomplish this by for example putting all your pointers into an array, and thus pass an array name, which is just a "tag name pointer", to a function.........

    hope this helps,

    Regards,
    matheo917

  14. #14
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    ok dude this stinks. all of this time, it's just been like this:

    the function was fine and all. but....for some reason i can only declare 51 variables of type ROOM, which is the name of my struct. weird eh? i suppose i'll have to somehow take out 4 rooms. unless there is a way to be able to declare more. i learned some stuff though, thanks for the help guys!
    Last edited by Leeman_s; 05-02-2002 at 05:30 PM.

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, 09:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 05:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM

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