Stack List problem

Hi I am trying to work with stacks for one of my projects. The problem I am facing right now is that i have declared two stacks as global variables. When I try to access them in a function say a(), everything works fine, but further in the execution when I try to access them in a second function say b(), the program just hangs. Anyone else has had the same problem?

Post your code!

Mark

Original code is quiet big. But this is sort of something I am trying to do.

#include <StackList.h>
StackList Snakestackx;
StackList Snakestacky;

void setup(){
}
void a(){
int a = Snakestackx.push(18);
int b = Snakestacky.push(18);
}

void b(){
int c = Snakestackx.pop();
int d = Snakestacky.pop();
}

void loop(){
a();
b();
}

What’s in Stacklist.h?

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

Original code is quiet big. But this is sort of something I am trying to do.

There is NOTHING in that code that proves you have a problem. Your "quiet big" code most likely does not respect the fact that the Arduino only has 2K (or 8K on a Mega) of memory. Stacks and limited memory generally do not go together.

Does the code you posted crash? If not, PaulS is probably right, it is a sizing problem.

Well I just tried to push 3 integers into each stack in one function and popped them back out into another. I am using the MEGA. Paul seems offended but I didn't want to put 500 lines (497 to be exact) of code here (where the rest of the code just works fine) and let you guys figure it out. That is why I didn't post the complete code.

Paul seems offended but I didn't want to put 500 lines (497 to be exact) of code here (where the rest of the code just works fine) and let you guys figure it out. That is why I didn't post the complete code.

I'm not offended. The code that you posted does not have any serial print statements, so you have no idea whether data is pushed onto a stack correctly, nor whether it is popped off the stack correctly.

So, you have no idea whether that sample illustrates your problem, or not.

It is that that I have an issue with. Posting 497 line code is not a problem. I have one class that I support that is more then 35000 lines. No, it is not for the Arduino. It's well (enough for me) commented, so I wouldn't have any problem with anyone else looking at it, if it was necessary to determine whether that code was a culprit, or not.

mfahad:
Well I just tried to push 3 integers into each stack in one function and popped them back out into another.

Post the library. Can't help without seeing that. Post code that reproduces the problem.

This is like another recent post where someone posted a single line of code and asked for help debugging it.