I need to define an array statically (in a *.h) file of size 12884901888 like.
unsigned char sram; //All of my code is C.
Above declaration gives error and does not work.
Because constants used in array declarations are unsigned int. But the constant i need to use (12884901888) is larger than the unsigned int limit.
How can i define the array as above, of size 12884901888 ?
P.S. I know many will say, optimize on that humongous array size, but i need to use same for some reason specific to my case.
Make the array dimension an unsigned long long.
unsigned char sram[12884901888ULL];
Is this for an embedded microcontroller? You can often get away with something like:
#define sram (*((unsigned char (*)) 0))
Unless your compiler implements bounds checking, the array size does not matter. In any case you do not want the compiler to attempt to reserve 12884901888 bytes, because linking will fail.
Converting 12884901888 to hexadecimal gives : 0x3-0000-0000 (I separated each group of 16 bits)
In other words, this array of unsigned bytes needs 3 times 4 Gig The compiler is supposed to generate 34 bits address pointer for this to work
I agree with finnw, you don't need to tell the compiler the size of the array. If you do specify the size, you will get a large OBJ file for the module and similarly large ELF/EXE for the final executable.