i have a very big array which is shared among many functions in many files in a vc project. My problem is, I have to declare it in main() and use extern in the header files. Since the array is too large for the stack i have to use static which makes it impossible to have the extern declaration in the header files.
How can I solve this problem?
EDIT:
What i did was as you said but i get error LNK2001: unresolved external symbol
Here is my global declaration and the extern declaration:
main.c
static unsigned char bit_table_[ROWS][COLUMNS];
hdr.h
extern unsigned char bit_table_[ROWS][COLUMNS];
ROWS and COLUMNS could grow as large as 1024 and 1048576 respectively
By making it
static, you’re avoiding overflowing the stack (the heap isn’t involved), but by placing it insidemainno other parts of your program can access it directly.To share between functions and files in the same program, you must define it outside of main, and put an
externdeclaration for it in a header that you’ll include in the other files that need to access it:big_array.c:
in big_array.h:
Then any other file that needs access to it just: