I do understand that the heap is an alternative, but I'm not concerned about making it work, I want to know why a large static local array would cause a crash.
Here is some code to illustrate how I declared the stack:
Version 1 - Use a global array:
Code:
LineSegment stack[MAXDEPTH];
int the_algorithm() {
LineSegment *sp = stack;
...
// code that uses the stack through 'sp'
...
}
Version 2 - Use a static local variable:
Code:
int the_algorithm() {
static LineSegment stack[MAXDEPTH];
LineSegment *sp = stack;
...
// code that uses the stack through 'sp'
...
}
The LineSegment struct:
Code:
typedef struct {
int x1, x2, y, dy;
} LineSegment;
Assume MAXDEPTH can be anywhere from 10,000 to 1,000,000.
[edit]
Also, I apologize since I don't think I was very clear. I know that this isn't defined by the standard and thus is implementation specific (I happen to be using the MinGW compiler for Windows), so I'm not expecting an answer that covers all platforms, just an idea of what my compiler might be doing under the covers here.
[/edit]