Static Local Variable vs. Global Variable
I'm wondering what the difference is between declaring a variable globally, and declaring it as a static local variable (aside from the obvious scope difference).
The reason for the question is: I was recently working on a graphical algorithm that uses an array (actually its a stack, but I'm going to call it an array or the terminology will get confusing).
The array needs to be rather large - large enough that storing it on the stack would be silly and crash-prone. So I decided to declare it globally, and all was good.
But then I started thinking, I only use the array inside of one function, and I really don't want anything else to access it. So I moved it into the function as a static local variable thinking that the compiler would store it in the data segment along with the globals. However, this causes the program to crash. I have since moved it back out to global scope, and once again all is good.
So clearly there is a difference in the way static local variables are allocated vs. global variables. What's going on here?